diff --git a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php index 2e659e94e9b..d208b4f7258 100644 --- a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php +++ b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php @@ -20,6 +20,7 @@ use Rector\BetterPhpDocParser\PhpDocNodeVisitor\ChangedPhpDocNodeVisitor; use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey; use Rector\BetterPhpDocParser\ValueObject\StartAndEnd; +use Rector\Core\Exception\ShouldNotHappenException; use Symplify\SimplePhpDocParser\PhpDocNodeTraverser; /** @@ -62,35 +63,18 @@ final class PhpDocInfoPrinter */ private const TAG_AND_SPACE_REGEX = '#(@.*?) \(#'; - /** - * @var int - */ - private $tokenCount; + private int $tokenCount = 0; - /** - * @var int - */ - private $currentTokenPosition; + private int $currentTokenPosition = 0; /** * @var mixed[] */ - private $tokens = []; + private array $tokens = []; - /** - * @var PhpDocNode - */ - private $phpDocNode; - - /** - * @var PhpDocInfo - */ - private $phpDocInfo; + private ?PhpDocInfo $phpDocInfo = null; - /** - * @var PhpDocNodeTraverser - */ - private $changedPhpDocNodeTraverser; + private PhpDocNodeTraverser $changedPhpDocNodeTraverser; public function __construct( private EmptyPhpDocDetector $emptyPhpDocDetector, @@ -133,7 +117,7 @@ public function printFormatPreserving(PhpDocInfo $phpDocInfo): string return (string) $phpDocInfo->getPhpDocNode(); } - $this->phpDocNode = $phpDocInfo->getPhpDocNode(); + $phpDocNode = $phpDocInfo->getPhpDocNode(); $this->tokens = $phpDocInfo->getTokens(); $this->tokenCount = $phpDocInfo->getTokenCount(); @@ -141,12 +125,21 @@ public function printFormatPreserving(PhpDocInfo $phpDocInfo): string $this->currentTokenPosition = 0; - $phpDocString = $this->printPhpDocNode($this->phpDocNode); + $phpDocString = $this->printPhpDocNode($phpDocNode); // hotfix of extra space with callable () return Strings::replace($phpDocString, self::CALLABLE_REGEX, 'callable('); } + public function getCurrentPhpDocInfo(): PhpDocInfo + { + if ($this->phpDocInfo === null) { + throw new ShouldNotHappenException(); + } + + return $this->phpDocInfo; + } + private function printPhpDocNode(PhpDocNode $phpDocNode): string { // no nodes were, so empty doc @@ -242,9 +235,9 @@ private function printDocChildNode( private function printEnd(string $output): string { - $lastTokenPosition = $this->phpDocNode->getAttribute( - PhpDocAttributeKey::LAST_PHP_DOC_TOKEN_POSITION - ) ?: $this->currentTokenPosition; + $lastTokenPosition = $this->getCurrentPhpDocInfo() + ->getPhpDocNode() + ->getAttribute(PhpDocAttributeKey::LAST_PHP_DOC_TOKEN_POSITION) ?: $this->currentTokenPosition; if ($lastTokenPosition === 0) { $lastTokenPosition = 1; } @@ -258,8 +251,10 @@ private function addTokensFromTo(string $output, int $from, int $to, bool $shoul $positionJumpSet = []; $removedStartAndEnds = $this->removeNodesStartAndEndResolver->resolve( - $this->phpDocInfo->getOriginalPhpDocNode(), - $this->phpDocNode, + $this->getCurrentPhpDocInfo() + ->getOriginalPhpDocNode(), + $this->getCurrentPhpDocInfo() + ->getPhpDocNode(), $this->tokens ); @@ -312,7 +307,8 @@ private function correctPreviouslyReprintedFirstNode(int $key, StartAndEnd $star $startTokenPosition = $startAndEnd->getStart(); - $tokens = $this->phpDocInfo->getTokens(); + $tokens = $this->getCurrentPhpDocInfo() + ->getTokens(); if (! isset($tokens[$startTokenPosition - 1])) { return; } @@ -333,7 +329,7 @@ private function shouldReprint(PhpDocChildNode $phpDocChildNode): bool private function standardPrintPhpDocChildNode(PhpDocChildNode $phpDocChildNode): string { - if ($this->phpDocInfo->isSingleLine()) { + if ($this->getCurrentPhpDocInfo()->isSingleLine()) { return ' ' . $phpDocChildNode; } diff --git a/packages/FamilyTree/NodeAnalyzer/PropertyUsageAnalyzer.php b/packages/FamilyTree/NodeAnalyzer/PropertyUsageAnalyzer.php index 7ba4f68139a..290f93e0e23 100644 --- a/packages/FamilyTree/NodeAnalyzer/PropertyUsageAnalyzer.php +++ b/packages/FamilyTree/NodeAnalyzer/PropertyUsageAnalyzer.php @@ -59,9 +59,7 @@ public function isPropertyFetchedInChildClass(Property $property): bool $isPropertyFetched = (bool) $this->betterNodeFinder->findFirst( $childClass->stmts, - function (Node $node) use ($propertyName): bool { - return $this->nodeNameResolver->isLocalPropertyFetchNamed($node, $propertyName); - } + fn (Node $node): bool => $this->nodeNameResolver->isLocalPropertyFetchNamed($node, $propertyName) ); if ($isPropertyFetched) { diff --git a/packages/NodeNestingScope/ScopeNestingComparator.php b/packages/NodeNestingScope/ScopeNestingComparator.php index 43f187e44ba..1f2bbf928d3 100644 --- a/packages/NodeNestingScope/ScopeNestingComparator.php +++ b/packages/NodeNestingScope/ScopeNestingComparator.php @@ -79,19 +79,19 @@ public function isInBothIfElseBranch(Node $foundParentNode, Expr $seekedExpr): b return false; } - $foundIfNode = $this->betterNodeFinder->find($foundParentNode->stmts, function ($node) use ($seekedExpr): bool { - return $this->nodeComparator->areNodesEqual($node, $seekedExpr); - }); + $foundIfNode = $this->betterNodeFinder->find( + $foundParentNode->stmts, + fn ($node): bool => $this->nodeComparator->areNodesEqual($node, $seekedExpr) + ); if ($foundParentNode->else === null) { return false; } - $foundElseNode = $this->betterNodeFinder->find($foundParentNode->else, function ($node) use ( - $seekedExpr - ): bool { - return $this->nodeComparator->areNodesEqual($node, $seekedExpr); - }); + $foundElseNode = $this->betterNodeFinder->find( + $foundParentNode->else, + fn ($node): bool => $this->nodeComparator->areNodesEqual($node, $seekedExpr) + ); if ($foundIfNode && $foundElseNode) { $this->doubleIfBranchExprs[] = $seekedExpr; diff --git a/phpstan.neon b/phpstan.neon index 28392bba656..8e1aeaca115 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -472,3 +472,8 @@ parameters: # fixed in dev-main - '#Class like namespace "Rector\\(.*?)" does not follow PSR\-4 configuration in composer\.json#' + + # deserves better architecture + - + message: '#Do not use chained method calls#' + path: packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php diff --git a/rules/CodeQuality/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php b/rules/CodeQuality/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php index f5a41bbdacc..86dad5465ab 100644 --- a/rules/CodeQuality/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php +++ b/rules/CodeQuality/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php @@ -78,9 +78,10 @@ public function refactor(Node $node): ?Node } if (! $node instanceof Assign) { - return ! (bool) $this->betterNodeFinder->find($node, function (Node $n) use ($arrayVariable) { - return $this->nodeComparator->areNodesEqual($arrayVariable, $n); - }); + return ! (bool) $this->betterNodeFinder->find( + $node, + fn (Node $n): bool => $this->nodeComparator->areNodesEqual($arrayVariable, $n) + ); } if (! $this->nodeComparator->areNodesEqual($arrayVariable, $node->var)) { diff --git a/rules/CodeQuality/Rector/Identical/GetClassToInstanceOfRector.php b/rules/CodeQuality/Rector/Identical/GetClassToInstanceOfRector.php index 3f89786efdb..2b642fe9e9b 100644 --- a/rules/CodeQuality/Rector/Identical/GetClassToInstanceOfRector.php +++ b/rules/CodeQuality/Rector/Identical/GetClassToInstanceOfRector.php @@ -63,12 +63,8 @@ public function refactor(Node $node): ?Node { $twoNodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode( $node, - function (Node $node): bool { - return $this->isClassReference($node); - }, - function (Node $node): bool { - return $this->isGetClassFuncCallNode($node); - } + fn (Node $node): bool => $this->isClassReference($node), + fn (Node $node): bool => $this->isGetClassFuncCallNode($node) ); if (! $twoNodeMatch instanceof TwoNodeMatch) { diff --git a/rules/CodeQuality/Rector/Identical/SimplifyArraySearchRector.php b/rules/CodeQuality/Rector/Identical/SimplifyArraySearchRector.php index f697bc0d922..29ed6bc5a6e 100644 --- a/rules/CodeQuality/Rector/Identical/SimplifyArraySearchRector.php +++ b/rules/CodeQuality/Rector/Identical/SimplifyArraySearchRector.php @@ -61,9 +61,7 @@ function (Node $node): bool { return $this->nodeNameResolver->isName($node, 'array_search'); }, - function (Node $node): bool { - return $this->valueResolver->isFalse($node); - } + fn (Node $node): bool => $this->valueResolver->isFalse($node) ); if (! $twoNodeMatch instanceof TwoNodeMatch) { diff --git a/rules/CodeQuality/Rector/Identical/SimplifyConditionsRector.php b/rules/CodeQuality/Rector/Identical/SimplifyConditionsRector.php index d40e1d01fac..5fea5a9ad14 100644 --- a/rules/CodeQuality/Rector/Identical/SimplifyConditionsRector.php +++ b/rules/CodeQuality/Rector/Identical/SimplifyConditionsRector.php @@ -73,12 +73,8 @@ private function processIdenticalAndNotIdentical(Identical $identical): ?Node { $twoNodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode( $identical, - function (Node $binaryOp): bool { - return $binaryOp instanceof Identical || $binaryOp instanceof NotIdentical; - }, - function (Node $binaryOp): bool { - return $this->valueResolver->isTrueOrFalse($binaryOp); - } + fn (Node $binaryOp): bool => $binaryOp instanceof Identical || $binaryOp instanceof NotIdentical, + fn (Node $binaryOp): bool => $this->valueResolver->isTrueOrFalse($binaryOp) ); if (! $twoNodeMatch instanceof TwoNodeMatch) { diff --git a/rules/CodeQuality/Rector/Ternary/SimplifyTautologyTernaryRector.php b/rules/CodeQuality/Rector/Ternary/SimplifyTautologyTernaryRector.php index b3a4351b268..15aaf346236 100644 --- a/rules/CodeQuality/Rector/Ternary/SimplifyTautologyTernaryRector.php +++ b/rules/CodeQuality/Rector/Ternary/SimplifyTautologyTernaryRector.php @@ -53,12 +53,8 @@ public function refactor(Node $node): ?Node $twoNodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode( $node->cond, - function (Node $leftNode) use ($node): bool { - return $this->nodeComparator->areNodesEqual($leftNode, $node->if); - }, - function (Node $leftNode) use ($node): bool { - return $this->nodeComparator->areNodesEqual($leftNode, $node->else); - } + fn (Node $leftNode): bool => $this->nodeComparator->areNodesEqual($leftNode, $node->if), + fn (Node $leftNode): bool => $this->nodeComparator->areNodesEqual($leftNode, $node->else) ); if (! $twoNodeMatch instanceof TwoNodeMatch) { diff --git a/rules/CodeQualityStrict/Rector/Variable/MoveVariableDeclarationNearReferenceRector.php b/rules/CodeQualityStrict/Rector/Variable/MoveVariableDeclarationNearReferenceRector.php index 2ba3fee9e56..306bb658f0f 100644 --- a/rules/CodeQualityStrict/Rector/Variable/MoveVariableDeclarationNearReferenceRector.php +++ b/rules/CodeQualityStrict/Rector/Variable/MoveVariableDeclarationNearReferenceRector.php @@ -136,9 +136,10 @@ private function isUsedAsArraykeyOrInsideIfCondition(Expression $expression, Var private function hasPropertyInExpr(Expression $expression, Expr $expr): bool { - return (bool) $this->betterNodeFinder->findFirst($expr, function (Node $node): bool { - return $node instanceof PropertyFetch || $node instanceof StaticPropertyFetch; - }); + return (bool) $this->betterNodeFinder->findFirst( + $expr, + fn (Node $node): bool => $node instanceof PropertyFetch || $node instanceof StaticPropertyFetch + ); } private function shouldSkipReAssign(Expression $expression, Assign $assign): bool @@ -204,11 +205,10 @@ private function isUsedAsArrayKey(?Node $node, Variable $variable): bool continue; } - $isFoundInKey = (bool) $this->betterNodeFinder->findFirst($dim, function (Node $node) use ( - $variable - ): bool { - return $this->nodeComparator->areNodesEqual($node, $variable); - }); + $isFoundInKey = (bool) $this->betterNodeFinder->findFirst( + $dim, + fn (Node $node): bool => $this->nodeComparator->areNodesEqual($node, $variable) + ); if ($isFoundInKey) { return true; } @@ -228,9 +228,7 @@ private function isInsideCondition(Expression $expression): bool private function hasReAssign(Expression $expression, Expr $expr): bool { $next = $expression->getAttribute(AttributeKey::NEXT_NODE); - $exprValues = $this->betterNodeFinder->find($expr, function (Node $node): bool { - return $node instanceof Variable; - }); + $exprValues = $this->betterNodeFinder->find($expr, fn (Node $node): bool => $node instanceof Variable); if ($exprValues === []) { return false; diff --git a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php index cde38b8c34f..e2ca3b002f2 100644 --- a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php +++ b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php @@ -109,11 +109,10 @@ function (array $matches): string { } $newVariable = new Variable($newVariableName); - $isFoundInPrevious = (bool) $this->betterNodeFinder->findFirstPrevious($node, function (Node $n) use ( - $newVariable - ): bool { - return $this->nodeComparator->areNodesEqual($n, $newVariable); - }); + $isFoundInPrevious = (bool) $this->betterNodeFinder->findFirstPrevious( + $node, + fn (Node $n): bool => $this->nodeComparator->areNodesEqual($n, $newVariable) + ); if ($isFoundInPrevious) { return null; diff --git a/rules/DeadCode/NodeCollector/NodeByTypeAndPositionCollector.php b/rules/DeadCode/NodeCollector/NodeByTypeAndPositionCollector.php index 81eab71bc81..7f5c8426909 100644 --- a/rules/DeadCode/NodeCollector/NodeByTypeAndPositionCollector.php +++ b/rules/DeadCode/NodeCollector/NodeByTypeAndPositionCollector.php @@ -80,9 +80,7 @@ private function sortByStart(array $nodesByTypeAndPosition): array { usort( $nodesByTypeAndPosition, - function (VariableNodeUse $firstVariableNodeUse, VariableNodeUse $secondVariableNodeUse): int { - return $firstVariableNodeUse->getStartTokenPosition() <=> $secondVariableNodeUse->getStartTokenPosition(); - } + fn (VariableNodeUse $firstVariableNodeUse, VariableNodeUse $secondVariableNodeUse): int => $firstVariableNodeUse->getStartTokenPosition() <=> $secondVariableNodeUse->getStartTokenPosition() ); return $nodesByTypeAndPosition; } diff --git a/rules/DeadCode/Rector/Array_/RemoveDuplicatedArrayKeyRector.php b/rules/DeadCode/Rector/Array_/RemoveDuplicatedArrayKeyRector.php index 0c0467958b2..5f3b90aae39 100644 --- a/rules/DeadCode/Rector/Array_/RemoveDuplicatedArrayKeyRector.php +++ b/rules/DeadCode/Rector/Array_/RemoveDuplicatedArrayKeyRector.php @@ -94,12 +94,8 @@ private function getArrayItemsWithDuplicatedKey(Array_ $array): array private function filterItemsWithSameKey(array $arrayItemsByKeys): array { /** @var ArrayItem[][] $arrayItemsByKeys */ - $arrayItemsByKeys = array_filter($arrayItemsByKeys, function (array $arrayItems): bool { - return count($arrayItems) > 1; - }); + $arrayItemsByKeys = array_filter($arrayItemsByKeys, fn (array $arrayItems): bool => count($arrayItems) > 1); - return array_filter($arrayItemsByKeys, function (array $arrayItems): bool { - return count($arrayItems) > 1; - }); + return array_filter($arrayItemsByKeys, fn (array $arrayItems): bool => count($arrayItems) > 1); } } diff --git a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php index 24d5feb8c8a..32b3c8ab50b 100644 --- a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php +++ b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php @@ -125,19 +125,16 @@ private function shouldSkip(Assign $assign): bool return $variable->name instanceof Variable && $this->betterNodeFinder->findFirstNext( $assign, - function (Node $node): bool { - return $node instanceof Variable; - } + fn (Node $node): bool => $node instanceof Variable ); } private function isUsed(Assign $assign, Variable $variable): bool { - $isUsedPrev = (bool) $this->betterNodeFinder->findFirstPreviousOfNode($variable, function (Node $node) use ( - $variable - ): bool { - return $this->usedVariableNameAnalyzer->isVariableNamed($node, $variable); - }); + $isUsedPrev = (bool) $this->betterNodeFinder->findFirstPreviousOfNode( + $variable, + fn (Node $node): bool => $this->usedVariableNameAnalyzer->isVariableNamed($node, $variable) + ); if ($isUsedPrev) { return true; @@ -184,14 +181,13 @@ private function isUsedInAssignExpr(Expr $expr, Assign $assign): bool continue; } - $previousAssign = $this->betterNodeFinder->findFirstPreviousOfNode($assign, function (Node $node) use ( + $previousAssign = $this->betterNodeFinder->findFirstPreviousOfNode( + $assign, + fn (Node $node): bool => $node instanceof Assign && $this->usedVariableNameAnalyzer->isVariableNamed( + $node->var, $variable - ): bool { - return $node instanceof Assign && $this->usedVariableNameAnalyzer->isVariableNamed( - $node->var, - $variable - ); - }); + ) + ); if ($previousAssign instanceof Assign) { return $this->isUsed($assign, $variable); diff --git a/rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php b/rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php index 5535032cb45..4097d119c7a 100644 --- a/rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php +++ b/rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php @@ -58,6 +58,10 @@ public function refactor(Node $node) return $this->removeNodeAndKeepComments($node); } + if ($livingCode === [$node->expr]) { + return null; + } + $firstExpr = array_shift($livingCode); $node->expr = $firstExpr; diff --git a/rules/DeadCode/Rector/Foreach_/RemoveUnusedForeachKeyRector.php b/rules/DeadCode/Rector/Foreach_/RemoveUnusedForeachKeyRector.php index 13c833f063e..910e6747053 100644 --- a/rules/DeadCode/Rector/Foreach_/RemoveUnusedForeachKeyRector.php +++ b/rules/DeadCode/Rector/Foreach_/RemoveUnusedForeachKeyRector.php @@ -55,11 +55,10 @@ public function refactor(Node $node): ?Node $keyVar = $node->keyVar; - $isNodeUsed = (bool) $this->betterNodeFinder->findFirst($node->stmts, function (Node $node) use ( - $keyVar - ): bool { - return $this->nodeComparator->areNodesEqual($node, $keyVar); - }); + $isNodeUsed = (bool) $this->betterNodeFinder->findFirst( + $node->stmts, + fn (Node $node): bool => $this->nodeComparator->areNodesEqual($node, $keyVar) + ); if ($isNodeUsed) { return null; diff --git a/rules/DeadCode/Rector/FunctionLike/RemoveOverriddenValuesRector.php b/rules/DeadCode/Rector/FunctionLike/RemoveOverriddenValuesRector.php index 3eb9efaf3c8..9ff397b5a7c 100644 --- a/rules/DeadCode/Rector/FunctionLike/RemoveOverriddenValuesRector.php +++ b/rules/DeadCode/Rector/FunctionLike/RemoveOverriddenValuesRector.php @@ -229,11 +229,10 @@ private function shouldRemoveAssignNode( /** @var Assign $assignNode */ $assignNode = $nodeByTypeAndPosition->getParentNode(); - $isVariableAssigned = (bool) $this->betterNodeFinder->findFirst($assignNode->expr, function (Node $node) use ( - $nodeByTypeAndPosition - ): bool { - return $this->nodeComparator->areNodesEqual($node, $nodeByTypeAndPosition->getVariableNode()); - }); + $isVariableAssigned = (bool) $this->betterNodeFinder->findFirst( + $assignNode->expr, + fn (Node $node): bool => $this->nodeComparator->areNodesEqual($node, $nodeByTypeAndPosition->getVariableNode()) + ); return ! $isVariableAssigned; } diff --git a/rules/DowngradePhp70/Rector/New_/DowngradeAnonymousClassRector.php b/rules/DowngradePhp70/Rector/New_/DowngradeAnonymousClassRector.php index eb0ccb6c817..4c7b371fbc6 100644 --- a/rules/DowngradePhp70/Rector/New_/DowngradeAnonymousClassRector.php +++ b/rules/DowngradePhp70/Rector/New_/DowngradeAnonymousClassRector.php @@ -127,8 +127,8 @@ public function refactor(Node $node): ?Node private function createAnonymousClassName(): string { - $fileInfo = $this->file->getSmartFileInfo(); + $smartFileInfo = $this->file->getSmartFileInfo(); - return self::ANONYMOUS_CLASS_PREFIX . md5($fileInfo->getRealPath()) . '__' . count($this->classes); + return self::ANONYMOUS_CLASS_PREFIX . md5($smartFileInfo->getRealPath()) . '__' . count($this->classes); } } diff --git a/rules/DowngradePhp70/Rector/Spaceship/DowngradeSpaceshipRector.php b/rules/DowngradePhp70/Rector/Spaceship/DowngradeSpaceshipRector.php index e1372fce83a..a92d65c2b61 100644 --- a/rules/DowngradePhp70/Rector/Spaceship/DowngradeSpaceshipRector.php +++ b/rules/DowngradePhp70/Rector/Spaceship/DowngradeSpaceshipRector.php @@ -109,11 +109,10 @@ private function getVariableAssign(Stmt $stmt, string $variableName = 'battleShi { $variable = new Variable($variableName); - $isFoundPrevious = (bool) $this->betterNodeFinder->findFirstPreviousOfNode($stmt, function (Node $node) use ( - $variable - ): bool { - return $node instanceof Variable && $this->nodeComparator->areNodesEqual($node, $variable); - }); + $isFoundPrevious = (bool) $this->betterNodeFinder->findFirstPreviousOfNode( + $stmt, + fn (Node $node): bool => $node instanceof Variable && $this->nodeComparator->areNodesEqual($node, $variable) + ); $count = 0; if ($isFoundPrevious) { diff --git a/rules/DowngradePhp70/Rector/String_/DowngradeGeneratedScalarTypesRector.php b/rules/DowngradePhp70/Rector/String_/DowngradeGeneratedScalarTypesRector.php index 8a7d39dd7d7..198f242b578 100644 --- a/rules/DowngradePhp70/Rector/String_/DowngradeGeneratedScalarTypesRector.php +++ b/rules/DowngradePhp70/Rector/String_/DowngradeGeneratedScalarTypesRector.php @@ -96,10 +96,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $fileInfo = $this->file->getSmartFileInfo(); + $smartFileInfo = $this->file->getSmartFileInfo(); // this rule is parsing strings, so it heavy on performance; to lower it, we'll process only known opt-in files - if (! $this->isRelevantFileInfo($fileInfo)) { + if (! $this->isRelevantFileInfo($smartFileInfo)) { return null; } diff --git a/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php b/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php index dcdbbfada47..b73b1a7558f 100644 --- a/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php +++ b/rules/DowngradePhp73/Rector/FuncCall/SetCookieOptionsArrayToArgumentsRector.php @@ -45,10 +45,7 @@ final class SetCookieOptionsArrayToArgumentsRector extends AbstractRector 6 => false, ]; - /** - * @var int - */ - private $highestIndex = 1; + private int $highestIndex = 1; public function getRuleDefinition(): RuleDefinition { diff --git a/rules/EarlyReturn/Rector/Foreach_/ReturnAfterToEarlyOnBreakRector.php b/rules/EarlyReturn/Rector/Foreach_/ReturnAfterToEarlyOnBreakRector.php index 016eb4efa56..b50ee43bb12 100644 --- a/rules/EarlyReturn/Rector/Foreach_/ReturnAfterToEarlyOnBreakRector.php +++ b/rules/EarlyReturn/Rector/Foreach_/ReturnAfterToEarlyOnBreakRector.php @@ -160,11 +160,10 @@ private function shouldSkip(Return_ $return, ?Expr $expr = null, Foreach_ $forea } // ensure the variable only used once in foreach - $usedVariable = $this->betterNodeFinder->find($foreach->stmts, function (Node $node) use ( - $assignVariable - ): bool { - return $this->nodeComparator->areNodesEqual($node, $assignVariable); - }); + $usedVariable = $this->betterNodeFinder->find( + $foreach->stmts, + fn (Node $node): bool => $this->nodeComparator->areNodesEqual($node, $assignVariable) + ); return count($usedVariable) > 1; } } diff --git a/rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php b/rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php index 3d8a105dd8f..740cf419825 100644 --- a/rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php +++ b/rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php @@ -183,11 +183,10 @@ private function isIfStmtExprUsedInNextReturn(If_ $if, Return_ $return): bool $ifExprs = $this->betterNodeFinder->findInstanceOf($if->stmts, Expr::class); foreach ($ifExprs as $ifExpr) { - $isExprFoundInReturn = (bool) $this->betterNodeFinder->findFirst($return->expr, function (Node $node) use ( - $ifExpr - ): bool { - return $this->nodeComparator->areNodesEqual($node, $ifExpr); - }); + $isExprFoundInReturn = (bool) $this->betterNodeFinder->findFirst( + $return->expr, + fn (Node $node): bool => $this->nodeComparator->areNodesEqual($node, $ifExpr) + ); if ($isExprFoundInReturn) { return true; } diff --git a/rules/EarlyReturn/Rector/Return_/PreparedValueToEarlyReturnRector.php b/rules/EarlyReturn/Rector/Return_/PreparedValueToEarlyReturnRector.php index 2ebd7e74bde..8552fa424c3 100644 --- a/rules/EarlyReturn/Rector/Return_/PreparedValueToEarlyReturnRector.php +++ b/rules/EarlyReturn/Rector/Return_/PreparedValueToEarlyReturnRector.php @@ -132,11 +132,10 @@ public function refactor(Node $node): ?Node private function isAssignVarUsedInIfCond(array $ifsBefore, ?Expr $expr): bool { foreach ($ifsBefore as $ifBefore) { - $isUsedInIfCond = (bool) $this->betterNodeFinder->findFirst($ifBefore->cond, function (Node $node) use ( - $expr - ): bool { - return $this->nodeComparator->areNodesEqual($node, $expr); - }); + $isUsedInIfCond = (bool) $this->betterNodeFinder->findFirst( + $ifBefore->cond, + fn (Node $node): bool => $this->nodeComparator->areNodesEqual($node, $expr) + ); if ($isUsedInIfCond) { return true; @@ -157,11 +156,10 @@ private function isPreviousVarUsedInAssignExpr(array $ifsBefore, Expr $expr): bo /** @var Assign $assign */ $assign = $expression->expr; - $isUsedInAssignExpr = (bool) $this->betterNodeFinder->findFirst($assign->expr, function (Node $node) use ( - $expr - ): bool { - return $this->nodeComparator->areNodesEqual($node, $expr); - }); + $isUsedInAssignExpr = (bool) $this->betterNodeFinder->findFirst( + $assign->expr, + fn (Node $node): bool => $this->nodeComparator->areNodesEqual($node, $expr) + ); if ($isUsedInAssignExpr) { return true; diff --git a/rules/Order/Rector/Class_/OrderFirstLevelClassStatementsRector.php b/rules/Order/Rector/Class_/OrderFirstLevelClassStatementsRector.php index 2dcfb73de88..2cc4470a3f9 100644 --- a/rules/Order/Rector/Class_/OrderFirstLevelClassStatementsRector.php +++ b/rules/Order/Rector/Class_/OrderFirstLevelClassStatementsRector.php @@ -83,10 +83,11 @@ private function getStmtsInDesiredPosition(array $stmts): array { uasort( $stmts, - function (Stmt $firstStmt, Stmt $secondStmt): int { - return [$this->resolveClassElementRank($firstStmt), $firstStmt->getLine()] - <=> [$this->resolveClassElementRank($secondStmt), $secondStmt->getLine()]; - } + fn (Stmt $firstStmt, Stmt $secondStmt): int => [ + $this->resolveClassElementRank($firstStmt), + $firstStmt->getLine(), + ] + <=> [$this->resolveClassElementRank($secondStmt), $secondStmt->getLine()] ); return $stmts; diff --git a/rules/Order/StmtVisibilitySorter.php b/rules/Order/StmtVisibilitySorter.php index f0b3032878f..d849b4b3bef 100644 --- a/rules/Order/StmtVisibilitySorter.php +++ b/rules/Order/StmtVisibilitySorter.php @@ -127,9 +127,7 @@ private function sortByRanksAndGetNames(array $rankeables): array { uasort( $rankeables, - function (RankeableInterface $firstRankeable, RankeableInterface $secondRankeable): int { - return $firstRankeable->getRanks() <=> $secondRankeable->getRanks(); - } + fn (RankeableInterface $firstRankeable, RankeableInterface $secondRankeable): int => $firstRankeable->getRanks() <=> $secondRankeable->getRanks() ); $names = []; diff --git a/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php b/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php index d83c2ecf9ff..f82b1394743 100644 --- a/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php +++ b/rules/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php @@ -42,7 +42,7 @@ final class AddDefaultValueForUndefinedVariableRector extends AbstractRector /** * @var string[] */ - private $definedVariables = []; + private array $definedVariables = []; public function getRuleDefinition(): RuleDefinition { diff --git a/rules/Php71/Rector/Assign/AssignArrayToStringRector.php b/rules/Php71/Rector/Assign/AssignArrayToStringRector.php index c641efe7b97..da6c67369b6 100644 --- a/rules/Php71/Rector/Assign/AssignArrayToStringRector.php +++ b/rules/Php71/Rector/Assign/AssignArrayToStringRector.php @@ -102,11 +102,10 @@ public function refactor(Node $node): ?Node return $node; } - $isFoundPrev = (bool) $this->betterNodeFinder->findFirstPreviousOfNode($variable, function (Node $node) use ( - $variable - ): bool { - return $this->nodeComparator->areNodesEqual($node, $variable); - }); + $isFoundPrev = (bool) $this->betterNodeFinder->findFirstPreviousOfNode( + $variable, + fn (Node $node): bool => $this->nodeComparator->areNodesEqual($node, $variable) + ); if (! $isFoundPrev) { return null; diff --git a/rules/Php71/Rector/Name/ReservedObjectRector.php b/rules/Php71/Rector/Name/ReservedObjectRector.php index 1e0dea43ccb..fb2f1f17c26 100644 --- a/rules/Php71/Rector/Name/ReservedObjectRector.php +++ b/rules/Php71/Rector/Name/ReservedObjectRector.php @@ -29,7 +29,7 @@ final class ReservedObjectRector extends AbstractRector implements ConfigurableR /** * @var array */ - private $reservedKeywordsToReplacements = []; + private array $reservedKeywordsToReplacements = []; public function getRuleDefinition(): RuleDefinition { diff --git a/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php b/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php index 4a9bf254211..7b9ad02028f 100644 --- a/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php +++ b/rules/Php80/NodeAnalyzer/SwitchAnalyzer.php @@ -37,9 +37,7 @@ public function hasEachCaseBreak(Switch_ $switch): bool public function hasEachCaseSingleStmt(Switch_ $switch): bool { foreach ($switch->cases as $case) { - $stmtsWithoutBreak = array_filter($case->stmts, function (Node $node): bool { - return ! $node instanceof Break_; - }); + $stmtsWithoutBreak = array_filter($case->stmts, fn (Node $node): bool => ! $node instanceof Break_); if (count($stmtsWithoutBreak) !== 1) { return false; diff --git a/rules/Php80/Rector/Switch_/ChangeSwitchToMatchRector.php b/rules/Php80/Rector/Switch_/ChangeSwitchToMatchRector.php index e49eae0276b..6f27188d123 100644 --- a/rules/Php80/Rector/Switch_/ChangeSwitchToMatchRector.php +++ b/rules/Php80/Rector/Switch_/ChangeSwitchToMatchRector.php @@ -138,11 +138,10 @@ public function refactor(Node $node): ?Node private function changeToAssign(Switch_ $switch, Match_ $match, Expr $assignExpr): Assign { - $prevInitializedAssign = $this->betterNodeFinder->findFirstPreviousOfNode($switch, function (Node $node) use ( - $assignExpr - ): bool { - return $node instanceof Assign && $this->nodeComparator->areNodesEqual($node->var, $assignExpr); - }); + $prevInitializedAssign = $this->betterNodeFinder->findFirstPreviousOfNode( + $switch, + fn (Node $node): bool => $node instanceof Assign && $this->nodeComparator->areNodesEqual($node->var, $assignExpr) + ); $assign = new Assign($assignExpr, $match); if ($prevInitializedAssign instanceof Assign) { diff --git a/rules/Privatization/Rector/Class_/RepeatedLiteralToClassConstantRector.php b/rules/Privatization/Rector/Class_/RepeatedLiteralToClassConstantRector.php index 888b70f0bb0..fe59de81e11 100644 --- a/rules/Privatization/Rector/Class_/RepeatedLiteralToClassConstantRector.php +++ b/rules/Privatization/Rector/Class_/RepeatedLiteralToClassConstantRector.php @@ -241,9 +241,7 @@ private function createConstName(string $value): string $parts = explode(self::UNDERSCORE, $value); $parts = array_map( - function (string $value): string { - return StaticRectorStrings::camelCaseToUnderscore($value); - }, + fn (string $value): string => StaticRectorStrings::camelCaseToUnderscore($value), $parts ); diff --git a/rules/Removing/NodeManipulator/ComplexNodeRemover.php b/rules/Removing/NodeManipulator/ComplexNodeRemover.php index a24fd6bf053..280a806a786 100644 --- a/rules/Removing/NodeManipulator/ComplexNodeRemover.php +++ b/rules/Removing/NodeManipulator/ComplexNodeRemover.php @@ -132,11 +132,10 @@ private function removeConstructorDependency(Assign $assign): void } foreach ($constructClassMethod->getParams() as $param) { - $variable = $this->betterNodeFinder->findFirst((array) $constructClassMethod->stmts, function (Node $node) use ( - $param - ): bool { - return $this->nodeComparator->areNodesEqual($param->var, $node); - }); + $variable = $this->betterNodeFinder->findFirst( + (array) $constructClassMethod->stmts, + fn (Node $node): bool => $this->nodeComparator->areNodesEqual($param->var, $node) + ); if (! $variable instanceof Node) { continue; diff --git a/rules/RemovingStatic/Rector/Class_/StaticTypeToSetterInjectionRector.php b/rules/RemovingStatic/Rector/Class_/StaticTypeToSetterInjectionRector.php index 97f36806288..acbd00a67ac 100644 --- a/rules/RemovingStatic/Rector/Class_/StaticTypeToSetterInjectionRector.php +++ b/rules/RemovingStatic/Rector/Class_/StaticTypeToSetterInjectionRector.php @@ -135,9 +135,7 @@ private function processClass(Class_ $class): Class_ $containsEntityFactoryStaticCall = (bool) $this->betterNodeFinder->findFirst( $class->stmts, - function (Node $node) use ($objectType): bool { - return $this->isEntityFactoryStaticCall($node, $objectType); - } + fn (Node $node): bool => $this->isEntityFactoryStaticCall($node, $objectType) ); if (! $containsEntityFactoryStaticCall) { diff --git a/rules/Renaming/NodeManipulator/ClassRenamer.php b/rules/Renaming/NodeManipulator/ClassRenamer.php index d5e235337d4..34947f0f6d5 100644 --- a/rules/Renaming/NodeManipulator/ClassRenamer.php +++ b/rules/Renaming/NodeManipulator/ClassRenamer.php @@ -139,9 +139,10 @@ private function refactorName(Name $name, array $oldToNewClasses): ?Name private function removeUseName(Name $oldName): void { - $uses = $this->betterNodeFinder->findFirstPreviousOfNode($oldName, function (Node $node) use ($oldName): bool { - return $node instanceof UseUse && $this->nodeNameResolver->areNamesEqual($node, $oldName); - }); + $uses = $this->betterNodeFinder->findFirstPreviousOfNode( + $oldName, + fn (Node $node): bool => $node instanceof UseUse && $this->nodeNameResolver->areNamesEqual($node, $oldName) + ); if (! $uses instanceof UseUse) { return; diff --git a/rules/Renaming/Rector/FileWithoutNamespace/PseudoNamespaceToNamespaceRector.php b/rules/Renaming/Rector/FileWithoutNamespace/PseudoNamespaceToNamespaceRector.php index 4e75a410441..4fe98c6631b 100644 --- a/rules/Renaming/Rector/FileWithoutNamespace/PseudoNamespaceToNamespaceRector.php +++ b/rules/Renaming/Rector/FileWithoutNamespace/PseudoNamespaceToNamespaceRector.php @@ -43,12 +43,9 @@ final class PseudoNamespaceToNamespaceRector extends AbstractRector implements C /** * @var PseudoNamespaceToNamespace[] */ - private $pseudoNamespacesToNamespaces = []; + private array $pseudoNamespacesToNamespaces = []; - /** - * @var string|null - */ - private $newNamespace; + private ?string $newNamespace = null; public function __construct( private PhpDocTypeRenamer $phpDocTypeRenamer diff --git a/src/Application/ApplicationFileProcessor.php b/src/Application/ApplicationFileProcessor.php index 85055adbb58..65f208c26da 100644 --- a/src/Application/ApplicationFileProcessor.php +++ b/src/Application/ApplicationFileProcessor.php @@ -47,9 +47,7 @@ public function run(array $files): void private function processFiles(array $files): void { foreach ($this->fileProcessors as $fileProcessor) { - $supportedFiles = array_filter($files, function (File $file) use ($fileProcessor): bool { - return $fileProcessor->supports($file); - }); + $supportedFiles = array_filter($files, fn (File $file): bool => $fileProcessor->supports($file)); $fileProcessor->process($supportedFiles); } diff --git a/src/Console/Command/ShowCommand.php b/src/Console/Command/ShowCommand.php index b30f0426074..63916212840 100644 --- a/src/Console/Command/ShowCommand.php +++ b/src/Console/Command/ShowCommand.php @@ -38,9 +38,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int private function reportLoadedRectors(): void { - $rectors = array_filter($this->rectors, function (RectorInterface $rector) { - return ! $rector instanceof PostRectorInterface; - }); + $rectors = array_filter( + $this->rectors, + fn (RectorInterface $rector): bool => ! $rector instanceof PostRectorInterface + ); $rectorCount = count($rectors); diff --git a/src/DependencyInjection/CompilerPass/DeprecationWarningCompilerPass.php b/src/DependencyInjection/CompilerPass/DeprecationWarningCompilerPass.php index 40b7546ddfa..f90f02733d4 100644 --- a/src/DependencyInjection/CompilerPass/DeprecationWarningCompilerPass.php +++ b/src/DependencyInjection/CompilerPass/DeprecationWarningCompilerPass.php @@ -19,14 +19,14 @@ final class DeprecationWarningCompilerPass implements CompilerPassInterface public function process(ContainerBuilder $containerBuilder): void { - $parametersBag = $containerBuilder->getParameterBag(); + $parameterBag = $containerBuilder->getParameterBag(); foreach (self::DEPRECATED_PARAMETERS as $parameter => $message) { - if (! $parametersBag->has($parameter)) { + if (! $parameterBag->has($parameter)) { continue; } - $setsParameters = $parametersBag->get($parameter); + $setsParameters = $parameterBag->get($parameter); if ($setsParameters === []) { continue; } diff --git a/src/FileSystem/PhpFilesFinder.php b/src/FileSystem/PhpFilesFinder.php index 1e199c9be0f..005103ffbfe 100644 --- a/src/FileSystem/PhpFilesFinder.php +++ b/src/FileSystem/PhpFilesFinder.php @@ -30,9 +30,10 @@ public function findInPaths(array $paths): array ); // filter out non-PHP php files, e.g. blade templates in Laravel - $phpFileInfos = array_filter($phpFileInfos, function (SmartFileInfo $smartFileInfo): bool { - return ! Strings::endsWith($smartFileInfo->getPathname(), '.blade.php'); - }); + $phpFileInfos = array_filter( + $phpFileInfos, + fn (SmartFileInfo $smartFileInfo): bool => ! Strings::endsWith($smartFileInfo->getPathname(), '.blade.php') + ); return $this->cachedFileInfoFilterAndReporter->filterFileInfos($phpFileInfos); } diff --git a/src/NodeManipulator/ClassManipulator.php b/src/NodeManipulator/ClassManipulator.php index 30f746e33b9..579823b440b 100644 --- a/src/NodeManipulator/ClassManipulator.php +++ b/src/NodeManipulator/ClassManipulator.php @@ -69,9 +69,10 @@ public function hasParentMethodOrInterface(ObjectType $objectType, string $metho */ public function getPrivatePropertyNames(Class_ $class): array { - $privateProperties = array_filter($class->getProperties(), function (Property $property): bool { - return $property->isPrivate(); - }); + $privateProperties = array_filter( + $class->getProperties(), + fn (Property $property): bool => $property->isPrivate() + ); return $this->nodeNameResolver->getNames($privateProperties); } diff --git a/src/NodeManipulator/ClassMethodAssignManipulator.php b/src/NodeManipulator/ClassMethodAssignManipulator.php index c06661bbb6d..d45a70f3c66 100644 --- a/src/NodeManipulator/ClassMethodAssignManipulator.php +++ b/src/NodeManipulator/ClassMethodAssignManipulator.php @@ -36,7 +36,7 @@ final class ClassMethodAssignManipulator /** * @var array */ - private $alreadyAddedClassMethodNames = []; + private array $alreadyAddedClassMethodNames = []; public function __construct( private BetterNodeFinder $betterNodeFinder, @@ -123,9 +123,10 @@ private function filterOutArrayDestructedVariables(array $variableAssigns, Class } }); - return array_filter($variableAssigns, function (Assign $assign) use ($arrayDestructionCreatedVariables): bool { - return ! $this->nodeNameResolver->isNames($assign->var, $arrayDestructionCreatedVariables); - }); + return array_filter( + $variableAssigns, + fn (Assign $assign): bool => ! $this->nodeNameResolver->isNames($assign->var, $arrayDestructionCreatedVariables) + ); } /** @@ -136,9 +137,10 @@ private function filterOutReferencedVariables(array $variableAssigns, ClassMetho { $referencedVariables = $this->collectReferenceVariableNames($classMethod); - return array_filter($variableAssigns, function (Assign $assign) use ($referencedVariables): bool { - return ! $this->nodeNameResolver->isNames($assign->var, $referencedVariables); - }); + return array_filter( + $variableAssigns, + fn (Assign $assign): bool => ! $this->nodeNameResolver->isNames($assign->var, $referencedVariables) + ); } /** diff --git a/src/NodeManipulator/ClassMethodManipulator.php b/src/NodeManipulator/ClassMethodManipulator.php index cf59595612e..cedb8c7074c 100644 --- a/src/NodeManipulator/ClassMethodManipulator.php +++ b/src/NodeManipulator/ClassMethodManipulator.php @@ -35,11 +35,10 @@ public function __construct( public function isParameterUsedInClassMethod(Param $param, ClassMethod $classMethod): bool { - $isUsedDirectly = (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node) use ( - $param - ): bool { - return $this->nodeComparator->areNodesEqual($node, $param->var); - }); + $isUsedDirectly = (bool) $this->betterNodeFinder->findFirst( + (array) $classMethod->stmts, + fn (Node $node): bool => $this->nodeComparator->areNodesEqual($node, $param->var) + ); if ($isUsedDirectly) { return true; diff --git a/src/NodeManipulator/VariableManipulator.php b/src/NodeManipulator/VariableManipulator.php index bc6350172ab..e0d1521bcc0 100644 --- a/src/NodeManipulator/VariableManipulator.php +++ b/src/NodeManipulator/VariableManipulator.php @@ -80,9 +80,10 @@ function (Node $node) use (&$assignsOfArrayToVariable) { */ public function filterOutChangedVariables(array $assignsOfArrayToVariable, ClassMethod $classMethod): array { - return array_filter($assignsOfArrayToVariable, function (Assign $assign) use ($classMethod): bool { - return $this->isReadOnlyVariable($classMethod, $assign); - }); + return array_filter( + $assignsOfArrayToVariable, + fn (Assign $assign): bool => $this->isReadOnlyVariable($classMethod, $assign) + ); } private function isTestCaseExpectedVariable(Variable $variable): bool diff --git a/src/NonPhpFile/Rector/RenameClassNonPhpRector.php b/src/NonPhpFile/Rector/RenameClassNonPhpRector.php index c0c43de1d23..d7c7fb40ab5 100644 --- a/src/NonPhpFile/Rector/RenameClassNonPhpRector.php +++ b/src/NonPhpFile/Rector/RenameClassNonPhpRector.php @@ -95,11 +95,11 @@ private function renameClasses(string $newContent, array $classRenames): string foreach ($classRenames as $oldClass => $newClass) { // the old class is without slashes, it can make mess as similar to a word in the text, so we have to be more strict about it $oldClassRegex = $this->createOldClassRegex($oldClass); - $newContent = Strings::replace($newContent, $oldClassRegex, function (array $match) use ( - $newClass - ): string { - return ($match['extra_space'] ?? '') . $newClass; - }); + $newContent = Strings::replace( + $newContent, + $oldClassRegex, + fn (array $match): string => ($match['extra_space'] ?? '') . $newClass + ); } return $newContent; diff --git a/src/Reporting/MissingRectorRulesReporter.php b/src/Reporting/MissingRectorRulesReporter.php index 90791d0c3f0..a4f3f7d748b 100644 --- a/src/Reporting/MissingRectorRulesReporter.php +++ b/src/Reporting/MissingRectorRulesReporter.php @@ -22,9 +22,10 @@ public function __construct( public function reportIfMissing(): ?int { - $activeRectors = array_filter($this->rectors, function (RectorInterface $rector): bool { - return ! $rector instanceof PostRectorInterface; - }); + $activeRectors = array_filter( + $this->rectors, + fn (RectorInterface $rector): bool => ! $rector instanceof PostRectorInterface + ); if ($activeRectors !== []) { return null; diff --git a/tests/Issues/Issue6420/Fixture/fixture.php.inc b/tests/Issues/Issue6420/Fixture/fixture.php.inc new file mode 100644 index 00000000000..f91b8b98156 --- /dev/null +++ b/tests/Issues/Issue6420/Fixture/fixture.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/tests/Issues/Issue6420/RenameFunctionWithRemoveDeadStmtRectorTest.php b/tests/Issues/Issue6420/RenameFunctionWithRemoveDeadStmtRectorTest.php new file mode 100644 index 00000000000..67c7be5fb0a --- /dev/null +++ b/tests/Issues/Issue6420/RenameFunctionWithRemoveDeadStmtRectorTest.php @@ -0,0 +1,36 @@ +doTestFileInfo($fileInfo); + } + + /** + * @return Iterator + */ + public function provideData(): Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Issues/Issue6420/config/configured_rule.php b/tests/Issues/Issue6420/config/configured_rule.php new file mode 100644 index 00000000000..da407fc3bd9 --- /dev/null +++ b/tests/Issues/Issue6420/config/configured_rule.php @@ -0,0 +1,16 @@ +services(); + $services->set(RemoveDeadStmtRector::class); + $services->set(RenameFunctionRector::class) + ->call('configure', [[ + RenameFunctionRector::OLD_FUNCTION_TO_NEW_FUNCTION => [ + 'preg_replace' => 'Safe\preg_replace', + ], + ]]); +};