From 128910963ad4fa18a25e5c6e52a54eebf99e07fa Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 29 Feb 2020 01:29:42 +0100 Subject: [PATCH 1/2] various fixes --- .../Rector/MethodCall/RemoveDefaultArgumentValueRector.php | 6 ++++++ .../src/Rector/Class_/AddSeeTestAnnotationRector.php | 5 ++++- .../AssertTrueFalseInternalTypeToSpecificMethodRector.php | 6 +++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php b/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php index f6f14a4a4997..07c37f6345b5 100644 --- a/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php +++ b/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php @@ -11,6 +11,8 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\FunctionLike; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name; use Rector\Core\Rector\AbstractRector; use Rector\Core\RectorDefinition\CodeSample; use Rector\Core\RectorDefinition\RectorDefinition; @@ -111,6 +113,10 @@ private function shouldSkip(Node $node): bool return false; } + if (! $node->name instanceof Identifier && ! $node->name instanceof Name) { + return true; + } + $functionName = $this->getName($node->name); if ($functionName === null) { return false; diff --git a/rules/phpunit/src/Rector/Class_/AddSeeTestAnnotationRector.php b/rules/phpunit/src/Rector/Class_/AddSeeTestAnnotationRector.php index fb646d27df94..6e223cc9a324 100644 --- a/rules/phpunit/src/Rector/Class_/AddSeeTestAnnotationRector.php +++ b/rules/phpunit/src/Rector/Class_/AddSeeTestAnnotationRector.php @@ -107,8 +107,11 @@ private function shouldSkipClass(Class_ $class, string $testCaseClassName): bool return true; } - /** @var PhpDocInfo $phpDocInfo */ + /** @var PhpDocInfo|null $phpDocInfo */ $phpDocInfo = $class->getAttribute(AttributeKey::PHP_DOC_INFO); + if ($phpDocInfo === null) { + return true; + } $seeTags = $phpDocInfo->getTagsByName('see'); diff --git a/rules/phpunit/src/Rector/SpecificMethod/AssertTrueFalseInternalTypeToSpecificMethodRector.php b/rules/phpunit/src/Rector/SpecificMethod/AssertTrueFalseInternalTypeToSpecificMethodRector.php index 668dcc1c4e5d..f1e386057915 100644 --- a/rules/phpunit/src/Rector/SpecificMethod/AssertTrueFalseInternalTypeToSpecificMethodRector.php +++ b/rules/phpunit/src/Rector/SpecificMethod/AssertTrueFalseInternalTypeToSpecificMethodRector.php @@ -92,9 +92,13 @@ public function refactor(Node $node): ?Node return null; } - /** @var FuncCall $firstArgumentValue */ + /** @var FuncCall|Node $firstArgumentValue */ $firstArgumentValue = $node->args[0]->value; + if (! $firstArgumentValue instanceof FuncCall) { + return null; + } + $functionName = $this->getName($firstArgumentValue); if (! isset(self::OLD_FUNCTIONS_TO_TYPES[$functionName])) { return null; From cabe6d5e62b20add6c5066128c5c5f31647a0c6f Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 29 Feb 2020 01:32:26 +0100 Subject: [PATCH 2/2] fix scoping of OxidEsales --- compiler/build/scoper.inc.php | 2 ++ .../src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/build/scoper.inc.php b/compiler/build/scoper.inc.php index de2efea971a0..050efd807136 100644 --- a/compiler/build/scoper.inc.php +++ b/compiler/build/scoper.inc.php @@ -168,5 +168,7 @@ function (string $filePath, string $prefix, string $content): string { 'PhpParser\*', // mimics https://github.com/phpstan/phpstan-src/commit/23d5ca04ab6213f53a0e6c2e77857b23a73aa41d 'Hoa\*', + // @see https://github.com/rectorphp/rector/issues/2955 + 'OxidEsales\*', ], ]; diff --git a/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php b/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php index 07c37f6345b5..34c18fa05f35 100644 --- a/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php +++ b/rules/dead-code/src/Rector/MethodCall/RemoveDefaultArgumentValueRector.php @@ -11,7 +11,6 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\FunctionLike; -use PhpParser\Node\Identifier; use PhpParser\Node\Name; use Rector\Core\Rector\AbstractRector; use Rector\Core\RectorDefinition\CodeSample; @@ -113,7 +112,7 @@ private function shouldSkip(Node $node): bool return false; } - if (! $node->name instanceof Identifier && ! $node->name instanceof Name) { + if (! $node->name instanceof Name) { return true; }