From 78a1e5a4e4e1c73b4c10562da11dabdbd8ff780e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 3 Dec 2018 19:14:34 +0100 Subject: [PATCH 1/3] fix cs Signed-off-by: Tomas Votruba --- src/PhpParser/Node/Commander/NodeAddingCommander.php | 5 +++-- src/PhpParser/Node/Commander/NodeRemovingCommander.php | 5 +++-- src/PhpParser/Node/Commander/PropertyAddingCommander.php | 7 +++++-- src/PhpParser/NodeTraverser/CallableNodeTraverser.php | 5 +++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/PhpParser/Node/Commander/NodeAddingCommander.php b/src/PhpParser/Node/Commander/NodeAddingCommander.php index 27816cb115c..9d103bc05f9 100644 --- a/src/PhpParser/Node/Commander/NodeAddingCommander.php +++ b/src/PhpParser/Node/Commander/NodeAddingCommander.php @@ -93,12 +93,12 @@ final class NodeAddingCommander implements CommanderInterface private function createNodeVisitor(): NodeVisitor { - return new class($this->nodesToAdd) extends NodeVisitorAbstract - { + return new class($this->nodesToAdd) extends NodeVisitorAbstract { /** * @var Stmt[][] */ private $nodesToAdd = []; + /** * @param Stmt[][] $nodesToAdd */ @@ -106,6 +106,7 @@ final class NodeAddingCommander implements CommanderInterface { $this->nodesToAdd = $nodesToAdd; } + /** * @return Node[]|Node|null */ diff --git a/src/PhpParser/Node/Commander/NodeRemovingCommander.php b/src/PhpParser/Node/Commander/NodeRemovingCommander.php index 4094da2ca30..0b18bc8ea34 100644 --- a/src/PhpParser/Node/Commander/NodeRemovingCommander.php +++ b/src/PhpParser/Node/Commander/NodeRemovingCommander.php @@ -51,12 +51,12 @@ final class NodeRemovingCommander implements CommanderInterface private function createNodeVisitor(): NodeVisitor { - return new class($this->nodesToRemove) extends NodeVisitorAbstract - { + return new class($this->nodesToRemove) extends NodeVisitorAbstract { /** * @var Stmt[] */ private $nodesToRemove = []; + /** * @param Stmt[] $nodesToRemove */ @@ -64,6 +64,7 @@ final class NodeRemovingCommander implements CommanderInterface { $this->nodesToRemove = $nodesToRemove; } + /** * @return int|Node|Node[]|null */ diff --git a/src/PhpParser/Node/Commander/PropertyAddingCommander.php b/src/PhpParser/Node/Commander/PropertyAddingCommander.php index 0a58d09df63..327544797a7 100644 --- a/src/PhpParser/Node/Commander/PropertyAddingCommander.php +++ b/src/PhpParser/Node/Commander/PropertyAddingCommander.php @@ -58,16 +58,17 @@ final class PropertyAddingCommander implements CommanderInterface private function createNodeVisitor(): NodeVisitor { - return new class($this->classMaintainer, $this->propertiesByClass) extends NodeVisitorAbstract - { + return new class($this->classMaintainer, $this->propertiesByClass) extends NodeVisitorAbstract { /** * @var ClassMaintainer */ private $classMaintainer; + /** * @var VariableInfo[][] */ private $propertiesByClass = []; + /** * @param VariableInfo[][] $propertiesByClass */ @@ -76,6 +77,7 @@ final class PropertyAddingCommander implements CommanderInterface $this->classMaintainer = $classMaintainer; $this->propertiesByClass = $propertiesByClass; } + public function enterNode(Node $node): ?Node { if (! $node instanceof Class_ || $node->isAnonymous()) { @@ -84,6 +86,7 @@ final class PropertyAddingCommander implements CommanderInterface return $this->processClassNode($node); } + private function processClassNode(Class_ $classNode): Class_ { $variableInfos = $this->propertiesByClass[spl_object_hash($classNode)] ?? []; diff --git a/src/PhpParser/NodeTraverser/CallableNodeTraverser.php b/src/PhpParser/NodeTraverser/CallableNodeTraverser.php index 46edcd9a44e..5bee7577e75 100644 --- a/src/PhpParser/NodeTraverser/CallableNodeTraverser.php +++ b/src/PhpParser/NodeTraverser/CallableNodeTraverser.php @@ -23,16 +23,17 @@ final class CallableNodeTraverser private function createNodeVisitor(callable $callable): NodeVisitor { - return new class($callable) extends NodeVisitorAbstract - { + return new class($callable) extends NodeVisitorAbstract { /** * @var callable */ private $callable; + public function __construct(callable $callable) { $this->callable = $callable; } + /** * @return int|Node|null */ From c16e48974ccdec0272c26c18c6e6ecc0774dee0e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 3 Dec 2018 19:19:21 +0100 Subject: [PATCH 2/3] resolve anonymous assert name phpstan vs php-parser incompatbility Signed-off-by: Tomas Votruba --- .../Integration/nikic/anon_class.php.inc | 3 +-- src/PhpParser/Printer/BetterStandardPrinter.php | 6 +++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/Php/tests/Rector/FunctionLike/ParamAndReturnScalarTypehintsRector/Integration/nikic/anon_class.php.inc b/packages/Php/tests/Rector/FunctionLike/ParamAndReturnScalarTypehintsRector/Integration/nikic/anon_class.php.inc index 6e4ca4a44d4..fdb71610c6c 100644 --- a/packages/Php/tests/Rector/FunctionLike/ParamAndReturnScalarTypehintsRector/Integration/nikic/anon_class.php.inc +++ b/packages/Php/tests/Rector/FunctionLike/ParamAndReturnScalarTypehintsRector/Integration/nikic/anon_class.php.inc @@ -13,8 +13,7 @@ new class { namespace Rector\Php\Tests\Rector\ClassMethod\ParamAndReturnScalarTypehintsRector\Integration\AnonClass; -new class -{ +new class { /** @param int $a */ public function test(int $a) {} }; diff --git a/src/PhpParser/Printer/BetterStandardPrinter.php b/src/PhpParser/Printer/BetterStandardPrinter.php index 2162472340b..c89bba35dd8 100644 --- a/src/PhpParser/Printer/BetterStandardPrinter.php +++ b/src/PhpParser/Printer/BetterStandardPrinter.php @@ -149,7 +149,11 @@ final class BetterStandardPrinter extends Standard if ($node->class->name instanceof Identifier) { $className = $node->class->name->toString(); if (Strings::startsWith($className, 'AnonymousClass')) { - $node->setAttribute(Attribute::ORIGINAL_NODE, null); + /** @var Class_ $originalNode */ + $originalNode = $node->class->getAttribute(Attribute::ORIGINAL_NODE); + $originalNode->name = null; + + $node->class->setAttribute(Attribute::ORIGINAL_NODE, $originalNode); $node->class->name = null; } } From 50eb735abdcc2a019a891ffe6f2d45421954f881 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 3 Dec 2018 19:35:42 +0100 Subject: [PATCH 3/3] fix cs Signed-off-by: Tomas Votruba --- src/DependencyInjection/Loader/TolerantRectorYamlFileLoader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DependencyInjection/Loader/TolerantRectorYamlFileLoader.php b/src/DependencyInjection/Loader/TolerantRectorYamlFileLoader.php index ae88101cd48..64222a9e157 100644 --- a/src/DependencyInjection/Loader/TolerantRectorYamlFileLoader.php +++ b/src/DependencyInjection/Loader/TolerantRectorYamlFileLoader.php @@ -35,7 +35,7 @@ final class TolerantRectorYamlFileLoader extends AbstractParameterMergingYamlFil /** * @param string $file - * @return array|mixed|mixed[] + * @return mixed|mixed[] */ protected function loadFile($file) {