Skip to content

Commit dd0c725

Browse files
authored
UnusedMatchResult: fix false positive with assign operators (#171)
1 parent 44cb256 commit dd0c725

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Visitor/UnusedMatchVisitor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PhpParser\Node\Arg;
77
use PhpParser\Node\Expr\ArrayItem;
88
use PhpParser\Node\Expr\Assign;
9+
use PhpParser\Node\Expr\AssignOp;
910
use PhpParser\Node\Expr\BinaryOp\Coalesce;
1011
use PhpParser\Node\Expr\Match_;
1112
use PhpParser\Node\Expr\MethodCall;
@@ -76,6 +77,7 @@ private function isUsed(Node $parent): bool
7677
{
7778
return $parent instanceof Throw_
7879
|| $parent instanceof Assign
80+
|| $parent instanceof AssignOp
7981
|| $parent instanceof MethodCall
8082
|| $parent instanceof Return_
8183
|| $parent instanceof Arg

tests/Rule/data/ForbidUnusedMatchResultRule/code.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public function testUsed(bool $bool): mixed
3333
},
3434
};
3535

36+
$b += match ($int) {
37+
0 => 0,
38+
default => 1,
39+
};
40+
3641
$this->use(match ($bool) {
3742
false => new LogicException(),
3843
true => new RuntimeException(),

0 commit comments

Comments
 (0)