From b680ac6e726d59e3a3918ce7568820b2760d3852 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 9 May 2025 09:58:13 +0200 Subject: [PATCH] skip magic first class callable --- .../Fixture/skip_magic_closure_name.php.inc | 27 +++++++++++++++++++ .../LocalArrayMethodCallableMatcher.php | 5 ++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 rules-tests/Symfony73/Rector/Class_/GetFunctionsToAsTwigFunctionAttributeRector/Fixture/skip_magic_closure_name.php.inc diff --git a/rules-tests/Symfony73/Rector/Class_/GetFunctionsToAsTwigFunctionAttributeRector/Fixture/skip_magic_closure_name.php.inc b/rules-tests/Symfony73/Rector/Class_/GetFunctionsToAsTwigFunctionAttributeRector/Fixture/skip_magic_closure_name.php.inc new file mode 100644 index 00000000..0d6360ec --- /dev/null +++ b/rules-tests/Symfony73/Rector/Class_/GetFunctionsToAsTwigFunctionAttributeRector/Fixture/skip_magic_closure_name.php.inc @@ -0,0 +1,27 @@ +{$magic}(...)), + ]; + } + + public function someFunction($value) + { + return $value; + } + + public function anotherFunction($value) + { + return $value; + } +} diff --git a/rules/Symfony73/NodeAnalyzer/LocalArrayMethodCallableMatcher.php b/rules/Symfony73/NodeAnalyzer/LocalArrayMethodCallableMatcher.php index 6075edf1..59f3fa14 100644 --- a/rules/Symfony73/NodeAnalyzer/LocalArrayMethodCallableMatcher.php +++ b/rules/Symfony73/NodeAnalyzer/LocalArrayMethodCallableMatcher.php @@ -10,14 +10,15 @@ use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; use PhpParser\Node\Scalar\String_; -use Webmozart\Assert\Assert; final class LocalArrayMethodCallableMatcher { public function match(Expr $expr): ?string { if ($expr instanceof MethodCall) { - Assert::isInstanceOf($expr->name, Identifier::class); + if (! $expr->name instanceof Identifier) { + return null; + } return $expr->name->toString(); }