From 9488eb5d07365dbf2244264214d1b3ead8d93cc9 Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Wed, 29 Jul 2020 03:37:48 +0200 Subject: [PATCH] add debug notes --- ...trolArrayAccessToAnnotatedControlVariableRector.php | 4 ++-- .../TranslateClassMethodToVariadicsRector.php | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rules/nette-code-quality/src/Rector/ArrayDimFetch/ChangeControlArrayAccessToAnnotatedControlVariableRector.php b/rules/nette-code-quality/src/Rector/ArrayDimFetch/ChangeControlArrayAccessToAnnotatedControlVariableRector.php index 967271a4e58..f5563776029 100644 --- a/rules/nette-code-quality/src/Rector/ArrayDimFetch/ChangeControlArrayAccessToAnnotatedControlVariableRector.php +++ b/rules/nette-code-quality/src/Rector/ArrayDimFetch/ChangeControlArrayAccessToAnnotatedControlVariableRector.php @@ -113,11 +113,11 @@ PHP { $controlTypes = $this->methodNamesByInputNamesResolver->resolveExpr($arrayDimFetch); if ($controlTypes === []) { - throw new NotImplementedYetException(); + throw new NotImplementedYetException($controlName); } if (! isset($controlTypes[$controlName])) { - throw new ShouldNotHappenException(); + throw new ShouldNotHappenException($controlName); } $controlType = $controlTypes[$controlName]; diff --git a/rules/nette/src/Rector/ClassMethod/TranslateClassMethodToVariadicsRector.php b/rules/nette/src/Rector/ClassMethod/TranslateClassMethodToVariadicsRector.php index 5484a9283b2..52eef998bec 100644 --- a/rules/nette/src/Rector/ClassMethod/TranslateClassMethodToVariadicsRector.php +++ b/rules/nette/src/Rector/ClassMethod/TranslateClassMethodToVariadicsRector.php @@ -9,7 +9,6 @@ use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp\Coalesce; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Identifier; use PhpParser\Node\Param; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Stmt\ClassMethod; @@ -104,7 +103,7 @@ PHP $secondParam->default = null; $secondParam->variadic = true; - $secondParam->var = new Identifier('$' . self::PARAMETERS); + $secondParam->var->name = self::PARAMETERS; return $node; } @@ -123,16 +122,17 @@ PHP } // instantiate - $assign = $this->createCoalesceAssign($paramName, $node); + $assign = $this->createCoalesceAssign($node); $currentStmt = $node->getAttribute(AttributeKey::CURRENT_STATEMENT); - $this->addNodeBeforeNode($assign, $currentStmt); + $positionNode = $currentStmt ?? $node; + $this->addNodeBeforeNode($assign, $positionNode); return NodeTraverser::STOP_TRAVERSAL; }); } - private function createCoalesceAssign(string $paramName, Variable $variable): Assign + private function createCoalesceAssign(Variable $variable): Assign { $arrayDimFetch = new ArrayDimFetch(new Variable(self::PARAMETERS), new LNumber(0)); $coalesce = new Coalesce($arrayDimFetch, $this->createNull());