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
2 changes: 1 addition & 1 deletion .github/workflows/build_scoped_rector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
# 1. copy files to $NESTED_DIRECTORY directory Exclude the scoped/nested directories to prevent rsync from copying in a loop
- run: rsync --exclude rector-build -av * rector-build --quiet

- run: rm -rf rector-build/rules-tests rector-build/tests rector-build/bin/generate-changelog.php rector-build/bin/validate-phpstan-version.php rector-build/vendor/tracy/tracy/examples rector-build/vendor/symfony/console/Tester rector-build/vendor/symfony/console/Event rector-build/vendor/symfony/console/EventListener rector-build/vendor/tracy/tracy/examples rector-build/vendor/tracy/tracy/src/Bridges rector-build/vendor/tracy/tracy/src/Tracy/Bar rector-build/vendor/tracy/tracy/src/Tracy/Session rector-build/vendor/symfony/service-contracts/Test
- run: rm -rf rector-build/rules-tests rector-build/tests rector-build/bin/generate-changelog.php rector-build/bin/validate-phpstan-version.php rector-build/vendor/tracy/tracy/examples rector-build/vendor/symfony/console/Tester rector-build/vendor/symfony/console/Event rector-build/vendor/symfony/console/EventListener rector-build/vendor/tracy/tracy/examples rector-build/vendor/tracy/tracy/src/Bridges rector-build/vendor/tracy/tracy/src/Tracy/Bar rector-build/vendor/tracy/tracy/src/Tracy/Session rector-build/vendor/symfony/service-contracts/Test rector-build/bin/check-before-after-same-fixtures.php rector-build/bin/no-php-file-in-fixtures.php

# 2. downgrade rector
- run: php -d memory_limit=-1 bin/rector process rector-build/bin rector-build/config rector-build/src rector-build/rules rector-build/vendor --config build/config/config-downgrade.php --ansi --no-diffs
Expand Down
30 changes: 15 additions & 15 deletions rules/Php84/Rector/Foreach_/ForeachToArrayAnyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ public function provideMinPhpVersion(): int
return PhpVersionFeature::ARRAY_ANY;
}

private function refactorBooleanAssignmentPattern(StmtsAwareInterface $node): ?Node
private function refactorBooleanAssignmentPattern(StmtsAwareInterface $stmtsAware): ?Node
{
foreach ($node->stmts as $key => $stmt) {
foreach ($stmtsAware->stmts as $key => $stmt) {
if (! $stmt instanceof Foreach_) {
continue;
}

$prevStmt = $node->stmts[$key - 1] ?? null;
$prevStmt = $stmtsAware->stmts[$key - 1] ?? null;
if (! $prevStmt instanceof Expression) {
continue;
}
Expand All @@ -135,7 +135,7 @@ private function refactorBooleanAssignmentPattern(StmtsAwareInterface $node): ?N
}

if ($this->stmtsManipulator->isVariableUsedInNextStmt(
$node,
$stmtsAware,
$key + 1,
(string) $this->getName($foreach->valueVar)
)) {
Expand Down Expand Up @@ -171,26 +171,26 @@ private function refactorBooleanAssignmentPattern(StmtsAwareInterface $node): ?N
$newAssign = new Assign($assignedVariable, $funcCall);
$newExpression = new Expression($newAssign);

unset($node->stmts[$key - 1]);
$node->stmts[$key] = $newExpression;
unset($stmtsAware->stmts[$key - 1]);
$stmtsAware->stmts[$key] = $newExpression;

$node->stmts = array_values($node->stmts);
$stmtsAware->stmts = array_values($stmtsAware->stmts);

return $node;
return $stmtsAware;
}

return null;
}

private function refactorEarlyReturnPattern(StmtsAwareInterface $node): ?Node
private function refactorEarlyReturnPattern(StmtsAwareInterface $stmtsAware): ?Node
{
foreach ($node->stmts as $key => $stmt) {
foreach ($stmtsAware->stmts as $key => $stmt) {
if (! $stmt instanceof Foreach_) {
continue;
}

$foreach = $stmt;
$nextStmt = $node->stmts[$key + 1] ?? null;
$nextStmt = $stmtsAware->stmts[$key + 1] ?? null;

if (! $nextStmt instanceof Return_) {
continue;
Expand Down Expand Up @@ -232,11 +232,11 @@ private function refactorEarlyReturnPattern(StmtsAwareInterface $node): ?Node

$funcCall = $this->nodeFactory->createFuncCall('array_any', [$foreach->expr, $arrowFunction]);

$node->stmts[$key] = new Return_($funcCall);
unset($node->stmts[$key + 1]);
$node->stmts = array_values($node->stmts);
$stmtsAware->stmts[$key] = new Return_($funcCall);
unset($stmtsAware->stmts[$key + 1]);
$stmtsAware->stmts = array_values($stmtsAware->stmts);

return $node;
return $stmtsAware;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function refactor(Node $node): ?Node
}

$hasChanged = \false;
$this->traverseNodesWithCallable((array) $node->stmts, function (Node $node) use (&$hasChanged) {
$this->traverseNodesWithCallable((array) $node->stmts, function (Node $node) use (&$hasChanged): int|Return_|null {
if ($node instanceof Class_ || $node instanceof Function_ || $node instanceof Closure) {
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}
Expand Down
Loading