Skip to content

Commit 1baaa31

Browse files
committed
feat: Add phpdoc tags for static analysis.
1 parent 46c405b commit 1baaa31

File tree

9 files changed

+68
-48
lines changed

9 files changed

+68
-48
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
],
2929
"require": {
3030
"php": ">= 7.4",
31-
"loophp/iterators": "^1.0"
31+
"loophp/iterators": "^1.1"
3232
},
3333
"require-dev": {
3434
"drupol/php-conventions": "^5",

phpstan-baseline.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Parameter \\#1 \\$other \\(iterable\\<TKey, T\\>\\) of method loophp\\\\PhpUnitIterableAssertions\\\\Constraint\\\\IsIdenticalIterable\\:\\:matches\\(\\) should be contravariant with parameter \\$other \\(mixed\\) of method PHPUnit\\\\Framework\\\\Constraint\\\\Constraint\\:\\:matches\\(\\)$#"
5+
count: 1
6+
path: src/Constraint/IsIdenticalIterable.php
7+
8+
-
9+
message: "#^Parameter \\#1 \\$other \\(iterable\\<TKey, T\\>\\) of method loophp\\\\PhpUnitIterableAssertions\\\\Constraint\\\\IsNotIdenticalIterable\\:\\:matches\\(\\) should be contravariant with parameter \\$other \\(mixed\\) of method PHPUnit\\\\Framework\\\\Constraint\\\\Constraint\\:\\:matches\\(\\)$#"
10+
count: 1
11+
path: src/Constraint/IsNotIdenticalIterable.php
12+

phpstan.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Parameter \\#1 \\$other \\(iterable\\<TKey, T\\>\\) of method loophp\\\\PhpUnitIterableAssertions\\\\Constraint\\\\IsIdenticalIterable\\:\\:matches\\(\\) should be contravariant with parameter \\$other \\(mixed\\) of method PHPUnit\\\\Framework\\\\Constraint\\\\Constraint\\:\\:matches\\(\\)$#"
5+
count: 1
6+
path: src/Constraint/IsIdenticalIterable.php
7+
8+
-
9+
message: "#^Parameter \\#1 \\$other \\(iterable\\<TKey, T\\>\\) of method loophp\\\\PhpUnitIterableAssertions\\\\Constraint\\\\IsNotIdenticalIterable\\:\\:matches\\(\\) should be contravariant with parameter \\$other \\(mixed\\) of method PHPUnit\\\\Framework\\\\Constraint\\\\Constraint\\:\\:matches\\(\\)$#"
10+
count: 1
11+
path: src/Constraint/IsNotIdenticalIterable.php
12+

psalm-baseline.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="v4.15.0@a1b5e489e6fcebe40cb804793d964e99fc347820">
3+
<file src="src/Constraint/IsIdenticalIterable.php">
4+
<MoreSpecificImplementedParamType occurrences="1">
5+
<code>$other</code>
6+
</MoreSpecificImplementedParamType>
7+
</file>
8+
<file src="src/Constraint/IsNotIdenticalIterable.php">
9+
<MoreSpecificImplementedParamType occurrences="1">
10+
<code>$other</code>
11+
</MoreSpecificImplementedParamType>
12+
</file>
13+
</files>

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns="https://getpsalm.org/schema/config"
55
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
6+
errorBaseline="psalm-baseline.xml"
67
>
78
<projectFiles>
89
<directory name="./src" />

src/Constraint/IsIdenticalIterable.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,22 @@
1313
use MultipleIterator;
1414
use PHPUnit\Framework\Constraint\Constraint;
1515

16+
/**
17+
* @template TKey
18+
* @template T
19+
*/
1620
final class IsIdenticalIterable extends Constraint
1721
{
1822
private int $limit;
1923

24+
/**
25+
* @var iterable<TKey, T>
26+
*/
2027
private iterable $subject;
2128

29+
/**
30+
* @param iterable<TKey, T> $subject
31+
*/
2232
public function __construct(iterable $subject, int $limit = 0)
2333
{
2434
$this->subject = $subject;
@@ -31,7 +41,7 @@ public function toString(): string
3141
}
3242

3343
/**
34-
* @param iterable $other
44+
* @param iterable<TKey, T> $other
3545
*/
3646
protected function matches($other): bool
3747
{

src/Constraint/IsNotIdenticalIterable.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,22 @@
1313
use MultipleIterator;
1414
use PHPUnit\Framework\Constraint\Constraint;
1515

16+
/**
17+
* @template TKey
18+
* @template T
19+
*/
1620
final class IsNotIdenticalIterable extends Constraint
1721
{
1822
private int $limit;
1923

24+
/**
25+
* @var iterable<TKey, T>
26+
*/
2027
private iterable $subject;
2128

29+
/**
30+
* @param iterable<TKey, T> $subject
31+
*/
2232
public function __construct(iterable $subject, int $limit = 0)
2333
{
2434
$this->subject = $subject;
@@ -31,7 +41,7 @@ public function toString(): string
3141
}
3242

3343
/**
34-
* @param iterable $other
44+
* @param iterable<TKey, T> $other
3545
*/
3646
protected function matches($other): bool
3747
{

tests/unit/Constraint/IsIdenticalIterableTest.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111

1212
use ArrayIterator;
1313
use ArrayObject;
14-
use IteratorAggregate;
14+
use loophp\iterators\ClosureIteratorAggregate;
1515
use loophp\PhpUnitIterableAssertions\Constraint\IsIdenticalIterable;
1616
use PHPUnit\Framework\TestCase;
17-
use Traversable;
1817

1918
/**
2019
* @coversDefaultClass \loophp\PhpUnitIterableAssertions
@@ -49,28 +48,10 @@ public function dataProvider()
4948
range('c', 'a'),
5049
];
5150

52-
$iterator = new class implements IteratorAggregate
53-
{
54-
private iterable $iterable;
55-
56-
public function withIterable(iterable $iterable): self
57-
{
58-
$clone = clone $this;
59-
$clone->iterable = $iterable;
60-
61-
return $clone;
62-
}
63-
64-
public function getIterator(): Traversable
65-
{
66-
yield from $this->iterable;
67-
}
68-
};
69-
7051
yield [
71-
$iterator->withIterable(range('a', 'c')),
72-
$iterator->withIterable(range('a', 'c')),
73-
range('c', 'a')
52+
new ClosureIteratorAggregate(static fn () => yield from range('a', 'c')),
53+
new ClosureIteratorAggregate(static fn () => yield from range('a', 'c')),
54+
range('c', 'a'),
7455
];
7556
}
7657

tests/unit/Constraint/IsNotIdenticalIterableTest.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111

1212
use ArrayIterator;
1313
use ArrayObject;
14-
use IteratorAggregate;
14+
use loophp\iterators\ClosureIteratorAggregate;
1515
use loophp\PhpUnitIterableAssertions\Constraint\IsNotIdenticalIterable;
1616
use PHPUnit\Framework\TestCase;
17-
use Traversable;
1817

1918
/**
2019
* @coversDefaultClass \loophp\PhpUnitIterableAssertions
@@ -49,27 +48,9 @@ public function dataProvider()
4948
range('a', 'c'),
5049
];
5150

52-
$iterator = new class implements IteratorAggregate
53-
{
54-
private iterable $iterable;
55-
56-
public function withIterable(iterable $iterable): self
57-
{
58-
$clone = clone $this;
59-
$clone->iterable = $iterable;
60-
61-
return $clone;
62-
}
63-
64-
public function getIterator(): Traversable
65-
{
66-
yield from $this->iterable;
67-
}
68-
};
69-
7051
yield [
71-
$iterator->withIterable(range('a', 'c')),
72-
$iterator->withIterable(range('c', 'a')),
52+
new ClosureIteratorAggregate(static fn () => yield from range('a', 'c')),
53+
new ClosureIteratorAggregate(static fn () => yield from range('c', 'a')),
7354
range('a', 'c'),
7455
];
7556
}

0 commit comments

Comments
 (0)