From b83524f932094e9437dc2ba3c2dc1a8652933b6e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 18 Nov 2023 13:54:46 +0000 Subject: [PATCH] Updated Rector to commit 6a2af1878843ade4b1890f9a1a04f815cc600fa4 https://github.com/rectorphp/rector-src/commit/6a2af1878843ade4b1890f9a1a04f815cc600fa4 [TypeDeclaration] Skip echo-ed on StrictArrayParamDimFetchRector (#5260) --- .../StrictArrayParamDimFetchRector.php | 33 ++++++++++++++++--- src/Application/VersionResolver.php | 4 +-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php b/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php index 253d90323b0..1632bb368e7 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/StrictArrayParamDimFetchRector.php @@ -17,6 +17,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Param; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; +use PhpParser\Node\Stmt\Echo_; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Function_; use PhpParser\NodeTraverser; @@ -132,6 +133,18 @@ CODE_SAMPLE }); return $isParamAccessedArrayDimFetch; } + private function isEchoed(Node $node, string $paramName) : bool + { + if (!$node instanceof Echo_) { + return \false; + } + foreach ($node->exprs as $expr) { + if ($expr instanceof Variable && $this->isName($expr, $paramName)) { + return \true; + } + } + return \false; + } private function shouldStop(Node $node, string $paramName) : bool { $nodeToCheck = null; @@ -148,12 +161,22 @@ CODE_SAMPLE if ($node instanceof AssignOpCoalesce) { $nodeToCheck = $node->var; } - if ($nodeToCheck instanceof MethodCall) { - return $nodeToCheck->var instanceof Variable && $this->isName($nodeToCheck->var, $paramName); + if ($this->isMethodCallOrArrayDimFetch($paramName, $nodeToCheck)) { + return \true; } - if ($nodeToCheck instanceof ArrayDimFetch) { - return $nodeToCheck->var instanceof Variable && $this->isName($nodeToCheck->var, $paramName); + if ($nodeToCheck instanceof Variable && $this->isName($nodeToCheck, $paramName)) { + return \true; } - return $nodeToCheck instanceof Variable && $this->isName($nodeToCheck, $paramName); + return $this->isEchoed($node, $paramName); + } + private function isMethodCallOrArrayDimFetch(string $paramName, ?Node $node) : bool + { + if ($node instanceof MethodCall) { + return $node->var instanceof Variable && $this->isName($node->var, $paramName); + } + if ($node instanceof ArrayDimFetch) { + return $node->var instanceof Variable && $this->isName($node->var, $paramName); + } + return \false; } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 7e137890726..d5175980604 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '03c7ab7a0f3b7a2ba106bef1ccf508d1b9b63850'; + public const PACKAGE_VERSION = '6a2af1878843ade4b1890f9a1a04f815cc600fa4'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-11-18 20:39:36'; + public const RELEASE_DATE = '2023-11-18 20:52:32'; /** * @var int */