diff --git a/phpstan.neon b/phpstan.neon index ded2a47bc19..8321117bd09 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -48,7 +48,12 @@ parameters: narrow_return: true ignoreErrors: + # required generics on interface array, not helpful - + message: '#Method (.*?)\:\:__construct\(\) has parameter#' + identifier: missingType.generics + - + message: '#(.*?) with generic interface (.*?)Interface does not specify its types#' identifier: missingType.generics # phpstan class instance @@ -135,7 +140,6 @@ parameters: # internal reflection - '#Instead of "new ClassReflection\(\)" use ReflectionProvider service or "\(new PHPStan\\Reflection\\ClassReflection\(\)\)" for static reflection to work#' - - '#Callable callable\(PHPStan\\Type\\Type\)\: PHPStan\\Type\\Type invoked with 2 parameters, 1 required#' # known value @@ -181,10 +185,15 @@ parameters: # fixture class - '#Class "Rector\\Tests\\Issues\\ScopeNotAvailable\\Variable\\ArrayItemForeachValueRector" is missing @see annotation with test case class reference#' + # classes are part of *.php.inc fixture - message: '#Class (.*?) not found#' paths: - - rules-tests/*/config/* + - rules-tests/Arguments/Rector/ClassMethod/ReplaceArgumentDefaultValueRector/config + - rules-tests/TypeDeclaration/Rector/ClassMethod/AddReturnTypeDeclarationRector/config + - rules-tests/Renaming/Rector/Name/RenameClassRector/config + - rules-tests/Renaming/Rector/MethodCall/RenameMethodRector/config + - rules-tests/Arguments/Rector/ClassMethod/ArgumentAdderRector/config - message: '#Function "(function_exists|dump_node)\(\)" cannot be used/left in the code#' @@ -334,12 +343,6 @@ parameters: identifier: arrayValues.list path: rules/CodingStyle/Application/UseImportsAdder.php - - - message: '#^Register "Rector\\Php74\\Rector\\Double\\RealToFloatTypeCastRector" service to "php74\.php" config set$#' - identifier: rector.upgradeDowngradeRegisteredInSet - count: 1 - path: rules/Php74/Rector/Double/RealToFloatTypeCastRector.php - - message: '#Offset float\|int\|string might not exist on string#' path: rules/Php70/EregToPcreTransformer.php @@ -387,14 +390,11 @@ parameters: - paths: - rules/TypeDeclaration/Rector/StmtsAwareInterface/IncreaseDeclareStrictTypesRector.php - - rules/TypeDeclaration/Rector/StmtsAwareInterface/DeclareStrictTypesRector.php identifier: rector.noOnlyNullReturnInRefactor - identifier: rector.noIntegerRefactorReturn paths: - - rules/Transform/Rector/ArrayDimFetch/ArrayDimFetchToMethodCallRector.php - # valid, as use REMOVE_NODE - rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php - rules/DeadCode/Rector/If_/RemoveDeadInstanceOfRector.php diff --git a/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php b/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php index 0aeea1d7918..8d9329bdbe6 100644 --- a/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php +++ b/src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php @@ -10,29 +10,10 @@ use PhpParser\Node\Stmt; use PhpParser\NodeTraverserInterface; use PhpParser\NodeVisitor; +use Rector\Exception\ShouldNotHappenException; abstract class AbstractImmutableNodeTraverser implements NodeTraverserInterface { - /** - * @deprecated Use NodeVisitor::DONT_TRAVERSE_CHILDREN instead. - */ - public const DONT_TRAVERSE_CHILDREN = NodeVisitor::DONT_TRAVERSE_CHILDREN; - - /** - * @deprecated Use NodeVisitor::STOP_TRAVERSAL instead. - */ - public const STOP_TRAVERSAL = NodeVisitor::STOP_TRAVERSAL; - - /** - * @deprecated Use NodeVisitor::REMOVE_NODE instead. - */ - public const REMOVE_NODE = NodeVisitor::REMOVE_NODE; - - /** - * @deprecated Use NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN instead. - */ - public const DONT_TRAVERSE_CURRENT_AND_CHILDREN = NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; - /** * @var list Visitors */ @@ -63,15 +44,9 @@ public function addVisitor(NodeVisitor $visitor): void $this->visitors[] = $visitor; } - /** - * Removes an added visitor. - */ public function removeVisitor(NodeVisitor $visitor): void { - $index = array_search($visitor, $this->visitors, true); - if ($index !== false) { - array_splice($this->visitors, $index, 1, []); - } + throw new ShouldNotHappenException('The immutable node traverser does not support removing visitors.'); } /** @@ -106,11 +81,6 @@ public function traverse(array $nodes): array */ abstract public function getVisitorsForNode(Node $node): array; - /** - * Recursively traverse a node. - * - * @param Node $node Node to traverse. - */ protected function traverseNode(Node $node): void { foreach ($node->getSubNodeNames() as $name) { @@ -189,10 +159,7 @@ protected function traverseNode(Node $node): void } /** - * Recursively traverse array (usually of nodes). - * - * @param Node[] $nodes Array to traverse - * + * @param Node[] $nodes * @return array Result of traversal (may be original array or changed one) */ protected function traverseArray(array $nodes): array @@ -285,16 +252,20 @@ protected function traverseArray(array $nodes): array private function ensureReplacementReasonable(Node $old, Node $new): void { - if ($old instanceof Stmt && $new instanceof Expr) { - throw new LogicException( - sprintf('Trying to replace statement (%s) ', $old->getType()) . sprintf( - 'with expression (%s). Are you missing a ', - $new->getType() - ) . 'Stmt_Expression wrapper?' - ); + if ($old instanceof Stmt) { + if ($new instanceof Expr) { + throw new LogicException( + sprintf('Trying to replace statement (%s) ', $old->getType()) . sprintf( + 'with expression (%s). Are you missing a ', + $new->getType() + ) . 'Stmt_Expression wrapper?' + ); + } + + return; } - if ($old instanceof Expr && $new instanceof Stmt) { + if ($new instanceof Stmt) { throw new LogicException( sprintf('Trying to replace expression (%s) ', $old->getType()) . sprintf( 'with statement (%s)', diff --git a/tests/PhpParser/NodeTraverser/RectorNodeTraverserTest.php b/tests/PhpParser/NodeTraverser/RectorNodeTraverserTest.php index 25b2462dceb..428dccdb296 100644 --- a/tests/PhpParser/NodeTraverser/RectorNodeTraverserTest.php +++ b/tests/PhpParser/NodeTraverser/RectorNodeTraverserTest.php @@ -76,20 +76,4 @@ public function testGetVisitorsForNodeWhenAllVisitorsMatch(): void $this->assertEquals([$this->ruleUsingClassRector, $this->ruleUsingClassLikeRector], $visitors); } - - public function testGetVisitorsForNodeUsesCachedValue(): void - { - $class = new Class_('test'); - $this->rectorNodeTraverser->addVisitor($this->ruleUsingClassRector); - $this->rectorNodeTraverser->addVisitor($this->ruleUsingClassLikeRector); - - $visitors = $this->rectorNodeTraverser->getVisitorsForNode($class); - - $this->assertEquals([$this->ruleUsingClassRector, $this->ruleUsingClassLikeRector], $visitors); - - $this->rectorNodeTraverser->removeVisitor($this->ruleUsingClassRector); - $visitors = $this->rectorNodeTraverser->getVisitorsForNode($class); - - $this->assertEquals([$this->ruleUsingClassRector, $this->ruleUsingClassLikeRector], $visitors); - } }