Skip to content

Commit 460bcbd

Browse files
committed
Updated Rector to commit ddb43f6c44b0d8fbb96bc5e5d9458d39ac8a9e25
rectorphp/rector-src@ddb43f6 [Php73] Handle key() called multiple times on ArrayKeyFirstLastRector (#6888)
1 parent 029ac13 commit 460bcbd

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ private function processArrayKeyFirstLast(StmtsAwareInterface $stmtsAware, bool
122122
}
123123
$newName = self::PREVIOUS_TO_NEW_FUNCTIONS[$this->getName($stmt->expr)];
124124
$keyFuncCall->name = new Name($newName);
125+
$this->changeNextKeyCall($stmtsAware, $key + 2, $resetOrEndFuncCall, $keyFuncCall->name);
125126
unset($stmtsAware->stmts[$key]);
126127
$hasChanged = \true;
127128
return $this->processArrayKeyFirstLast($stmtsAware, $hasChanged, $key + 2);
@@ -131,6 +132,24 @@ private function processArrayKeyFirstLast(StmtsAwareInterface $stmtsAware, bool
131132
}
132133
return null;
133134
}
135+
private function changeNextKeyCall(StmtsAwareInterface $stmtsAware, int $key, FuncCall $resetOrEndFuncCall, Name $newName) : void
136+
{
137+
$counter = \count($stmtsAware->stmts);
138+
for ($nextKey = $key; $nextKey < $counter; ++$nextKey) {
139+
if (!isset($stmtsAware->stmts[$nextKey])) {
140+
break;
141+
}
142+
if ($stmtsAware->stmts[$nextKey] instanceof Expression && !$this->shouldSkip($stmtsAware->stmts[$nextKey])) {
143+
$this->processArrayKeyFirstLast($stmtsAware, \true, $nextKey);
144+
break;
145+
}
146+
$keyFuncCall = $this->resolveKeyFuncCall($stmtsAware->stmts[$nextKey], $resetOrEndFuncCall);
147+
if (!$keyFuncCall instanceof FuncCall) {
148+
continue;
149+
}
150+
$keyFuncCall->name = $newName;
151+
}
152+
}
134153
private function resolveKeyFuncCall(Stmt $nextStmt, FuncCall $resetOrEndFuncCall) : ?FuncCall
135154
{
136155
if ($resetOrEndFuncCall->isFirstClassCallable()) {

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '2329798fd80ecffa34bd580efae0c52400ef2932';
22+
public const PACKAGE_VERSION = 'ddb43f6c44b0d8fbb96bc5e5d9458d39ac8a9e25';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-05-07 17:40:27';
27+
public const RELEASE_DATE = '2025-05-09 04:45:11';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)