Skip to content

Commit e20f1c9

Browse files
authored
[Php85] Skip under unset() on ArrayFirstLastRector (#7752)
* [Php85] Skip under unset() on ArrayFirstLastRector * fix
1 parent 7962073 commit e20f1c9

File tree

2 files changed

+19
-0
lines changed

2 files changed

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

rules/Php85/Rector/ArrayDimFetch/ArrayFirstLastRector.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node;
88
use PhpParser\Node\Expr\ArrayDimFetch;
99
use PhpParser\Node\Expr\FuncCall;
10+
use Rector\NodeTypeResolver\Node\AttributeKey;
1011
use Rector\PHPStan\ScopeFetcher;
1112
use Rector\Rector\AbstractRector;
1213
use Rector\ValueObject\PhpVersionFeature;
@@ -88,6 +89,10 @@ public function refactor(Node $node): ?FuncCall
8889
return null;
8990
}
9091

92+
if ($node->getAttribute(AttributeKey::IS_UNSET_VAR)) {
93+
return null;
94+
}
95+
9196
$functionName = $this->isName($node->dim, self::ARRAY_KEY_FIRST)
9297
? 'array_first'
9398
: 'array_last';

0 commit comments

Comments
 (0)