diff --git a/rules/CodeQuality/Rector/MethodCall/AssertSameResponseCodeWithDebugContentsRector.php b/rules/CodeQuality/Rector/MethodCall/AssertSameResponseCodeWithDebugContentsRector.php index 3c06a147..17511153 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertSameResponseCodeWithDebugContentsRector.php +++ b/rules/CodeQuality/Rector/MethodCall/AssertSameResponseCodeWithDebugContentsRector.php @@ -129,17 +129,17 @@ private function matchResponseExpr(Expr $expr): ?Expr return null; } - $varType = $this->nodeTypeResolver->getType($expr->var); - if (! $varType instanceof ObjectType) { + // must be status method call + if (! $this->isName($expr->name, 'getStatusCode')) { return null; } - if (! $varType->isInstanceof(ResponseClass::BASIC)->yes()) { + $varType = $this->nodeTypeResolver->getType($expr->var); + if (! $varType instanceof ObjectType) { return null; } - // must be status method call - if (! $this->isName($expr->name, 'getStatusCode')) { + if (! $varType->isInstanceof(ResponseClass::BASIC)->yes()) { return null; } diff --git a/rules/Symfony25/Rector/MethodCall/AddViolationToBuildViolationRector.php b/rules/Symfony25/Rector/MethodCall/AddViolationToBuildViolationRector.php index 7000451f..f9356694 100644 --- a/rules/Symfony25/Rector/MethodCall/AddViolationToBuildViolationRector.php +++ b/rules/Symfony25/Rector/MethodCall/AddViolationToBuildViolationRector.php @@ -66,6 +66,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?MethodCall { + if (! $this->isName($node->name, 'addViolationAt')) { + return null; + } + $objectType = $this->nodeTypeResolver->getType($node->var); if (! $objectType instanceof ObjectType) { return null; @@ -76,10 +80,6 @@ public function refactor(Node $node): ?MethodCall return null; } - if (! $this->isName($node->name, 'addViolationAt')) { - return null; - } - $args = $node->getArgs(); $path = $args[0]; $message = $args[1]; diff --git a/rules/Symfony33/Rector/ClassConstFetch/ConsoleExceptionToErrorEventConstantRector.php b/rules/Symfony33/Rector/ClassConstFetch/ConsoleExceptionToErrorEventConstantRector.php index 198f97e0..410ff068 100644 --- a/rules/Symfony33/Rector/ClassConstFetch/ConsoleExceptionToErrorEventConstantRector.php +++ b/rules/Symfony33/Rector/ClassConstFetch/ConsoleExceptionToErrorEventConstantRector.php @@ -60,22 +60,21 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if ($node instanceof ClassConstFetch && ( + if ($node instanceof String_) { + if ($node->value !== 'console.exception') { + return null; + } + + return $this->nodeFactory->createClassConstFetch($this->consoleEventsObjectType->getClassName(), 'ERROR'); + } + + if ( $this->isObjectType($node->class, $this->consoleEventsObjectType) && $this->isName($node->name, 'EXCEPTION') - ) ) { return $this->nodeFactory->createClassConstFetch($this->consoleEventsObjectType->getClassName(), 'ERROR'); } - if (! $node instanceof String_) { - return null; - } - - if ($node->value !== 'console.exception') { - return null; - } - - return $this->nodeFactory->createClassConstFetch($this->consoleEventsObjectType->getClassName(), 'ERROR'); + return null; } } diff --git a/rules/Symfony40/Rector/MethodCall/ContainerBuilderCompileEnvArgumentRector.php b/rules/Symfony40/Rector/MethodCall/ContainerBuilderCompileEnvArgumentRector.php index 356e7e6f..2288dbdf 100644 --- a/rules/Symfony40/Rector/MethodCall/ContainerBuilderCompileEnvArgumentRector.php +++ b/rules/Symfony40/Rector/MethodCall/ContainerBuilderCompileEnvArgumentRector.php @@ -64,6 +64,10 @@ public function refactor(Node $node): ?Node return null; } + if (count($node->args) === 1) { + return null; + } + if (! $this->isObjectType( $node->var, new ObjectType('Symfony\Component\DependencyInjection\ContainerBuilder') @@ -71,10 +75,6 @@ public function refactor(Node $node): ?Node return null; } - if (count($node->args) === 1) { - return null; - } - $node->args = $this->nodeFactory->createArgs([$this->nodeFactory->createTrue()]); return $node; diff --git a/rules/Symfony40/Rector/MethodCall/VarDumperTestTraitMethodArgsRector.php b/rules/Symfony40/Rector/MethodCall/VarDumperTestTraitMethodArgsRector.php index 611cfa40..c79e417c 100644 --- a/rules/Symfony40/Rector/MethodCall/VarDumperTestTraitMethodArgsRector.php +++ b/rules/Symfony40/Rector/MethodCall/VarDumperTestTraitMethodArgsRector.php @@ -60,6 +60,10 @@ public function refactor(Node $node): ?Node return null; } + if (count($node->args) <= 2) { + return null; + } + if (! $this->isObjectType( $node->var, new ObjectType('Symfony\Component\VarDumper\Test\VarDumperTestTrait') @@ -67,10 +71,6 @@ public function refactor(Node $node): ?Node return null; } - if (count($node->args) <= 2) { - return null; - } - $secondArg = $node->args[2]; if (! $secondArg instanceof Arg) { return null; diff --git a/rules/Symfony44/Rector/MethodCall/AuthorizationCheckerIsGrantedExtractorRector.php b/rules/Symfony44/Rector/MethodCall/AuthorizationCheckerIsGrantedExtractorRector.php index 1746ca65..aca2a043 100644 --- a/rules/Symfony44/Rector/MethodCall/AuthorizationCheckerIsGrantedExtractorRector.php +++ b/rules/Symfony44/Rector/MethodCall/AuthorizationCheckerIsGrantedExtractorRector.php @@ -113,6 +113,10 @@ public function refactor(Node $node): MethodCall|BooleanOr|null return null; } + if (! $this->isName($node->name, 'isGranted')) { + return null; + } + $objectType = $this->nodeTypeResolver->getType($node->var); if (! $objectType instanceof ObjectType) { return null; @@ -123,10 +127,6 @@ public function refactor(Node $node): MethodCall|BooleanOr|null return null; } - if (! $this->isName($node->name, 'isGranted')) { - return null; - } - return $this->handleIsGranted($node); } diff --git a/rules/Symfony81/Rector/MethodCall/RenameCopyOnWindowsOptionToFollowSymlinksRector.php b/rules/Symfony81/Rector/MethodCall/RenameCopyOnWindowsOptionToFollowSymlinksRector.php index 24e8175b..f25cb862 100644 --- a/rules/Symfony81/Rector/MethodCall/RenameCopyOnWindowsOptionToFollowSymlinksRector.php +++ b/rules/Symfony81/Rector/MethodCall/RenameCopyOnWindowsOptionToFollowSymlinksRector.php @@ -83,11 +83,11 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if (! $this->isObjectType($node->var, new ObjectType('Symfony\Component\Filesystem\Filesystem'))) { + if (! $this->isName($node->name, 'mirror')) { return null; } - if (! $this->isName($node->name, 'mirror')) { + if (! $this->isObjectType($node->var, new ObjectType('Symfony\Component\Filesystem\Filesystem'))) { return null; }