Skip to content

Commit 83dfe85

Browse files
committed
final touch: handle also as assign op
1 parent 3b16e4f commit 83dfe85

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
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+
}

rules-tests/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector/Fixture/skip_in_write_context.php.inc renamed to rules-tests/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector/Fixture/skip_as_assign_variable.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ declare(strict_types=1);
44

55
namespace Rector\Tests\Php85\Rector\ArrayDimFetch\ArrayFirstLastRector\Fixture;
66

7-
final class SkipInWriteContext
7+
final class SkipAsAssignVariable
88
{
9-
public function run($result, $lastInsertedId)
9+
public function asAssign($result, $lastInsertedId)
1010
{
1111
$result[\array_key_first($result)] = $lastInsertedId;
1212
}

rules/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ private function shouldSkip(ArrayDimFetch $arrayDimFetch, Node $scopeNode): bool
184184
return true;
185185
}
186186

187+
if ($arrayDimFetch->getAttribute(AttributeKey::IS_ASSIGN_OP_VAR) === true) {
188+
return true;
189+
}
190+
187191
return (bool) $arrayDimFetch->getAttribute(AttributeKey::IS_UNSET_VAR);
188192
}
189193
}

0 commit comments

Comments
 (0)