Skip to content

Commit 789646b

Browse files
committed
1 parent c8460a0 commit 789646b

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

rules-tests/Symfony73/Rector/Class_/GetFunctionsToAsTwigFunctionAttributeRector/Fixture/skip_difference_class.php.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ final class SkipDifferentClass extends AbstractExtension
1010
{
1111
return [
1212
new \Twig\TwigFunction('some_function', [DifferentClass::class, 'someFunction']),
13-
new \Twig\TwigFunction('some_function', $this->someFunction(...)),
1413
];
1514
}
1615

rules-tests/Symfony73/Rector/Class_/GetFunctionsToAsTwigFunctionAttributeRector/Fixture/some_get_functions.php.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ final class SomeGetFunctions extends AbstractExtension
3737

3838
namespace Rector\Symfony\Tests\Symfony73\Rector\Class_\GetFunctionsToAsTwigFunctionAttributeRector\Fixture;
3939

40+
use Twig\Extension\AbstractExtension;
41+
4042
final class SomeGetFunctions
4143
{
4244
#[\Twig\Attribute\AsTwigFunction('some_function')]

rules/Symfony73/GetMethodToAsTwigAttributeTransformer.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpParser\Node\AttributeGroup;
1010
use PhpParser\Node\Expr;
1111
use PhpParser\Node\Expr\Array_;
12+
use PhpParser\Node\Expr\CallLike;
1213
use PhpParser\Node\Expr\MethodCall;
1314
use PhpParser\Node\Expr\New_;
1415
use PhpParser\Node\Name\FullyQualified;
@@ -18,7 +19,10 @@
1819
use PhpParser\Node\Stmt\Return_;
1920
use PHPStan\Reflection\ReflectionProvider;
2021
use PHPStan\Type\ObjectType;
22+
use Rector\NodeNameResolver\NodeNameResolver;
23+
use Rector\NodeTypeResolver\NodeTypeResolver;
2124
use Rector\Privatization\NodeManipulator\VisibilityManipulator;
25+
use Rector\Symfony\Enum\TwigClass;
2226
use Rector\Symfony\Symfony73\NodeAnalyzer\LocalArrayMethodCallableMatcher;
2327
use Rector\Symfony\Symfony73\NodeRemover\ReturnEmptyArrayMethodRemover;
2428

@@ -31,7 +35,9 @@ public function __construct(
3135
private LocalArrayMethodCallableMatcher $localArrayMethodCallableMatcher,
3236
private ReturnEmptyArrayMethodRemover $returnEmptyArrayMethodRemover,
3337
private ReflectionProvider $reflectionProvider,
34-
private VisibilityManipulator $visibilityManipulator
38+
private VisibilityManipulator $visibilityManipulator,
39+
private NodeNameResolver $nodeNameResolver,
40+
private NodeTypeResolver $nodeTypeResolver
3541
) {
3642
}
3743

@@ -53,7 +59,6 @@ public function transformClassGetMethodToAttributeMarker(
5359
}
5460

5561
$hasChanged = false;
56-
5762
foreach ((array) $getMethod->stmts as $stmt) {
5863
// handle return array simple case
5964
if (! $stmt instanceof Return_) {
@@ -110,6 +115,10 @@ public function transformClassGetMethodToAttributeMarker(
110115
$this->returnEmptyArrayMethodRemover->removeClassMethodIfArrayEmpty($class, $returnArray, $methodName);
111116
}
112117

118+
if ($hasChanged && $class->extends instanceof FullyQualified && $class->extends->toString() == TwigClass::TWIG_EXTENSION) {
119+
$class->extends = null;
120+
}
121+
113122
return $hasChanged;
114123
}
115124

0 commit comments

Comments
 (0)