Skip to content

Commit 732278e

Browse files
authored
[Php85] Skip as assigned var/op on ArrayFirstLastRector (#7843)
* [Php85] Skip as assigned var on ArrayFirstLastRector * fix * fix * final touch: handle also as assign op
1 parent 52350dd commit 732278e

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Php85\Rector\ArrayDimFetch\ArrayFirstLastRector\Fixture;
6+
7+
final class SkipAsAssignOp
8+
{
9+
public function run($result, $lastInsertedId)
10+
{
11+
$result[\array_key_first($result)] += $lastInsertedId;
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\Php85\Rector\ArrayDimFetch\ArrayFirstLastRector\Fixture;
6+
7+
final class SkipAsAssignVariable
8+
{
9+
public function asAssign($result, $lastInsertedId)
10+
{
11+
$result[\array_key_first($result)] = $lastInsertedId;
12+
}
13+
}

rules/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ private function shouldSkip(ArrayDimFetch $arrayDimFetch, Node $scopeNode): bool
180180
return true;
181181
}
182182

183+
if ($arrayDimFetch->getAttribute(AttributeKey::IS_BEING_ASSIGNED) === true) {
184+
return true;
185+
}
186+
187+
if ($arrayDimFetch->getAttribute(AttributeKey::IS_ASSIGN_OP_VAR) === true) {
188+
return true;
189+
}
190+
183191
return (bool) $arrayDimFetch->getAttribute(AttributeKey::IS_UNSET_VAR);
184192
}
185193
}

0 commit comments

Comments
 (0)