Skip to content

Commit e093bf1

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

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

phpcs.xml.dist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<rule ref="DMS"/>
1414

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

src/ArrayAccessible.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
use ArrayIterator;
88
use IteratorAggregate;
99
use Traversable;
10+
1011
use function array_key_exists;
1112

1213
class ArrayAccessible implements ArrayAccess, IteratorAggregate
1314
{
1415
/**
1516
* @var mixed[]
1617
*/
17-
private $array;
18+
private array $array;
1819

1920
/**
2021
* @param mixed[] $array
@@ -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: 10 additions & 6 deletions
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;
@@ -26,11 +27,8 @@ final class ArraySubset extends Constraint
2627
/**
2728
* @var iterable|mixed[]
2829
*/
29-
private $subset;
30-
/**
31-
* @var bool
32-
*/
33-
private $strict;
30+
private iterable $subset;
31+
private bool $strict;
3432

3533
/**
3634
* @param mixed[] $subset
@@ -52,7 +50,8 @@ public function __construct(iterable $subset, bool $strict = false)
5250
* failure.
5351
*
5452
* @param mixed[]|ArrayAccess $other
55-
* @return mixed[]|null|bool
53+
*
54+
* @return mixed[]|bool|null
5655
*
5756
* @throws ExpectationFailedException
5857
* @throws InvalidArgumentException
@@ -69,9 +68,11 @@ public function evaluate($other, string $description = '', bool $returnResult =
6968
} else {
7069
$result = $other == $patched;
7170
}
71+
7272
if ($returnResult) {
7373
return $result;
7474
}
75+
7576
if ($result) {
7677
return null;
7778
}
@@ -120,12 +121,15 @@ private function toArray(iterable $other): array
120121
if (is_array($other)) {
121122
return $other;
122123
}
124+
123125
if ($other instanceof ArrayObject) {
124126
return $other->getArrayCopy();
125127
}
128+
126129
if ($other instanceof Traversable) {
127130
return iterator_to_array($other);
128131
}
132+
129133
// Keep BC even if we know that array would not be the expected one
130134
return (array) $other;
131135
}

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)