Skip to content

Commit a719486

Browse files
committed
Fix UnusedClosureUsesRule for already traversed match
Closes phpstan/phpstan-phpunit#190
1 parent 5b7bb23 commit a719486

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

.github/workflows/e2e-tests.yml

+2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ jobs:
153153
extensions: ""
154154
- script: "bin/phpstan analyse -l 8 tests/e2e/anon-class/Granularity.php"
155155
extensions: ""
156+
- script: "bin/phpstan analyse -l 8 e2e/phpstan-phpunit-190/test.php -c e2e/phpstan-phpunit-190/test.neon"
157+
extensions: ""
156158

157159
steps:
158160
- name: "Checkout"

e2e/phpstan-phpunit-190/test.neon

Whitespace-only changes.

e2e/phpstan-phpunit-190/test.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php // lint >= 8.1
2+
3+
namespace PhpstanPhpUnit190;
4+
5+
class FoobarTest
6+
{
7+
public function testBaz(): int
8+
{
9+
$matcher = new self();
10+
$this->acceptCallback(static function (string $test) use ($matcher): string {
11+
match ($matcher->testBaz()) {
12+
1 => 1,
13+
2 => 2,
14+
default => new \LogicException()
15+
};
16+
17+
return $test;
18+
});
19+
20+
return 1;
21+
}
22+
23+
public function acceptCallback(callable $cb): void
24+
{
25+
26+
}
27+
}

src/Node/Expr/AlwaysRememberedExpr.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class AlwaysRememberedExpr extends Expr implements VirtualNode
1010
{
1111

12-
public function __construct(private Expr $expr, private Type $type, private Type $nativeType)
12+
public function __construct(public Expr $expr, private Type $type, private Type $nativeType)
1313
{
1414
parent::__construct([]);
1515
}
@@ -39,7 +39,7 @@ public function getType(): string
3939
*/
4040
public function getSubNodeNames(): array
4141
{
42-
return [];
42+
return ['expr'];
4343
}
4444

4545
}

0 commit comments

Comments
 (0)