Skip to content

Commit e4b0299

Browse files
committed
Handle PHPCS errors
Handle the new issues from updated coding standard.
1 parent f2ae6f0 commit e4b0299

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

phpcs.xml.dist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint"/>
1515
</rule>
1616

17-
<!-- <rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators">-->
18-
<!-- <exclude-pattern>src/Constraint/ArraySubset.php</exclude-pattern>-->
19-
<!-- </rule>-->
17+
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators.DisallowedEqualOperator">
18+
<exclude-pattern>src/Constraint/ArraySubset.php</exclude-pattern>
19+
</rule>
2020
</ruleset>

src/ArrayAccessible.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use ArrayIterator;
88
use IteratorAggregate;
99
use Traversable;
10+
1011
use function array_key_exists;
1112

1213
class ArrayAccessible implements ArrayAccess, IteratorAggregate
@@ -63,6 +64,9 @@ public function offsetUnset($offset): void
6364
unset($this->array[$offset]);
6465
}
6566

67+
/**
68+
* @return mixed[]
69+
*/
6670
public function getIterator(): Traversable
6771
{
6872
return new ArrayIterator($this->array);

src/ArraySubsetAsserts.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPUnit\Framework\Assert as PhpUnitAssert;
1010
use PHPUnit\Framework\ExpectationFailedException;
1111
use PHPUnit\Framework\InvalidArgumentException;
12+
1213
use function is_array;
1314

1415
trait ArraySubsetAsserts
@@ -31,12 +32,14 @@ public static function assertArraySubset($subset, $array, bool $checkForObjectId
3132
'array or ArrayAccess'
3233
);
3334
}
35+
3436
if (! (is_array($array) || $array instanceof ArrayAccess)) {
3537
throw InvalidArgumentException::create(
3638
2,
3739
'array or ArrayAccess'
3840
);
3941
}
42+
4043
$constraint = new ArraySubset($subset, $checkForObjectIdentity);
4144
PhpUnitAssert::assertThat($array, $constraint, $message);
4245
}

src/Constraint/ArraySubset.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use SebastianBergmann\Comparator\ComparisonFailure;
1111
use SebastianBergmann\RecursionContext\InvalidArgumentException;
1212
use Traversable;
13+
1314
use function array_replace_recursive;
1415
use function is_array;
1516
use function iterator_to_array;
@@ -27,6 +28,7 @@ final class ArraySubset extends Constraint
2728
* @var iterable|mixed[]
2829
*/
2930
private $subset;
31+
3032
/**
3133
* @var bool
3234
*/
@@ -52,7 +54,8 @@ public function __construct(iterable $subset, bool $strict = false)
5254
* failure.
5355
*
5456
* @param mixed[]|ArrayAccess $other
55-
* @return mixed[]|null|bool
57+
*
58+
* @return mixed[]|bool|null
5659
*
5760
* @throws ExpectationFailedException
5861
* @throws InvalidArgumentException
@@ -69,9 +72,11 @@ public function evaluate($other, string $description = '', bool $returnResult =
6972
} else {
7073
$result = $other == $patched;
7174
}
75+
7276
if ($returnResult) {
7377
return $result;
7478
}
79+
7580
if ($result) {
7681
return null;
7782
}
@@ -120,12 +125,15 @@ private function toArray(iterable $other): array
120125
if (is_array($other)) {
121126
return $other;
122127
}
128+
123129
if ($other instanceof ArrayObject) {
124130
return $other->getArrayCopy();
125131
}
132+
126133
if ($other instanceof Traversable) {
127134
return iterator_to_array($other);
128135
}
136+
129137
// Keep BC even if we know that array would not be the expected one
130138
return (array) $other;
131139
}

tests/Unit/Constraint/ArraySubsetTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use ReflectionClass;
1414
use SebastianBergmann\RecursionContext\InvalidArgumentException;
1515
use Traversable;
16+
1617
use function sprintf;
1718

1819
final class ArraySubsetTest extends TestCase
@@ -53,13 +54,13 @@ public static function evaluateDataProvider(): array
5354
/**
5455
* @param array|Traversable|mixed[] $subset
5556
* @param array|Traversable|mixed[] $other
56-
* @param bool $strict
5757
*
5858
* @throws ExpectationFailedException
5959
* @throws InvalidArgumentException
60+
*
6061
* @dataProvider evaluateDataProvider
6162
*/
62-
public function testEvaluate(bool $expected, $subset, $other, $strict): void
63+
public function testEvaluate(bool $expected, $subset, $other, bool $strict): void
6364
{
6465
$constraint = new ArraySubset($subset, $strict);
6566

0 commit comments

Comments
 (0)