Skip to content

Commit

Permalink
Merge #470 - Restrict param type of OptionsArray::merge
Browse files Browse the repository at this point in the history
Pull-request: #470

Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Jun 29, 2023
2 parents f9c7db5 + 5293688 commit 6aac9c1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
3 changes: 0 additions & 3 deletions psalm-baseline.xml
Expand Up @@ -477,9 +477,6 @@
<code><![CDATA[! empty($option['equals']) && $option['equals']]]></code>
<code><![CDATA[$option['equals']]]></code>
</RedundantCondition>
<RedundantConditionGivenDocblockType>
<code>$options instanceof self</code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Components/OrderKeyword.php">
<MoreSpecificImplementedParamType>
Expand Down
20 changes: 3 additions & 17 deletions src/Components/OptionsArray.php
Expand Up @@ -24,21 +24,13 @@
*/
final class OptionsArray implements Component
{
/**
* ArrayObj of selected options.
*
* @var array<int, mixed>
*/
public array $options = [];

/**
* @param array<int, mixed> $options The array of options. Options that have a value
* must be an array with at least two keys `name` and
* `expr` or `value`.
*/
public function __construct(array $options = [])
public function __construct(public array $options = [])
{
$this->options = $options;
}

/**
Expand Down Expand Up @@ -350,16 +342,10 @@ public function remove($key): bool
/**
* Merges the specified options with these ones. Values with same ID will be
* replaced.
*
* @param array<int, mixed>|OptionsArray $options the options to be merged
*/
public function merge($options): void
public function merge(OptionsArray $options): void
{
if (is_array($options)) {
$this->options = array_merge_recursive($this->options, $options);
} elseif ($options instanceof self) {
$this->options = array_merge_recursive($this->options, $options->options);
}
$this->options = array_merge_recursive($this->options, $options->options);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Components/OptionsArrayTest.php
Expand Up @@ -109,7 +109,7 @@ public function testRemove(): void
public function testMerge(): void
{
$component = new OptionsArray(['a']);
$component->merge(['b', 'c']);
$component->merge(new OptionsArray(['b', 'c']));
$this->assertEquals($component->options, ['a', 'b', 'c']);
}

Expand Down

0 comments on commit 6aac9c1

Please sign in to comment.