Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php


namespace Rector\Tests\Php73\Rector\FuncCall\ArrayKeyFirstLastRector\Fixture;

function skipExecutionHasNextNext(array $arr) {
reset($arr);
while ($key !== null) {
$key = key($arr);
$value = current($arr);
if ($key === null) {
break;
}
echo $key . ": " . $value . PHP_EOL;
next($arr);
}
}

?>
6 changes: 3 additions & 3 deletions rules/Php73/Rector/FuncCall/ArrayKeyFirstLastRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private function processArrayKeyFirstLast(
continue;
}

if ($this->hasPrevCallNext($stmtsAware, $key + 2, $totalKeys, $keyFuncCall)) {
if ($this->hasInternalPointerChangeNext($stmtsAware, $key + 1, $totalKeys, $keyFuncCall)) {
Comment thread
samsonasik marked this conversation as resolved.
continue;
}

Expand Down Expand Up @@ -183,7 +183,7 @@ private function resolveKeyFuncCall(Stmt $nextStmt, FuncCall $resetOrEndFuncCall
});
}

private function hasPrevCallNext(
private function hasInternalPointerChangeNext(
StmtsAwareInterface $stmtsAware,
int $nextKey,
int $totalKeys,
Expand All @@ -201,7 +201,7 @@ function (Node $subNode) use ($funcCall): bool {
return false;
}

if (! $this->isName($subNode, 'prev')) {
if (! $this->isNames($subNode, ['prev', 'next'])) {
return false;
}

Expand Down