From 50dd99e8852a7f300eff736deb61923051b233f8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Mon, 2 May 2022 15:45:11 +0700 Subject: [PATCH 1/2] [CodeQuality] Skip CallableThisArrayToAnonymousFunctionRector when inside of Attribute --- .../Fixture/skip_in_attribute.php.inc | 22 +++++++++++++++++++ .../Source/LocaleUtils.php | 13 +++++++++++ 2 files changed, 35 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Fixture/skip_in_attribute.php.inc create mode 100644 rules-tests/CodeQuality/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Source/LocaleUtils.php diff --git a/rules-tests/CodeQuality/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Fixture/skip_in_attribute.php.inc b/rules-tests/CodeQuality/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Fixture/skip_in_attribute.php.inc new file mode 100644 index 00000000000..371874dbccb --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Fixture/skip_in_attribute.php.inc @@ -0,0 +1,22 @@ +locale; + } + + public function setLocale(?string $locale): Account + { + $this->locale = $locale; + return $this; + } +} diff --git a/rules-tests/CodeQuality/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Source/LocaleUtils.php b/rules-tests/CodeQuality/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Source/LocaleUtils.php new file mode 100644 index 00000000000..311405b3db3 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Source/LocaleUtils.php @@ -0,0 +1,13 @@ + Date: Mon, 2 May 2022 15:47:57 +0700 Subject: [PATCH 2/2] Fixed :tada: --- .../NodeAnalyzer/ArrayCallableMethodMatcher.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/NodeCollector/NodeAnalyzer/ArrayCallableMethodMatcher.php b/packages/NodeCollector/NodeAnalyzer/ArrayCallableMethodMatcher.php index 8925c513f7f..f7cc845669b 100644 --- a/packages/NodeCollector/NodeAnalyzer/ArrayCallableMethodMatcher.php +++ b/packages/NodeCollector/NodeAnalyzer/ArrayCallableMethodMatcher.php @@ -5,6 +5,7 @@ namespace Rector\NodeCollector\NodeAnalyzer; use PhpParser\Node\Arg; +use PhpParser\Node\Attribute; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\ClassConstFetch; @@ -71,6 +72,11 @@ public function match(Array_ $array): null | ArrayCallableDynamicMethod | ArrayC return null; } + $isInAttribute = (bool) $this->betterNodeFinder->findParentType($array, Attribute::class); + if ($isInAttribute) { + return null; + } + $values = $this->valueResolver->getValue($array); $className = $calleeType->getClassName(); $secondItemValue = $items[1]->value;