Skip to content

Commit 5ea0c40

Browse files
committed
add explicit attribute name arg, to improve context
1 parent 55e6ba9 commit 5ea0c40

7 files changed

Lines changed: 25 additions & 24 deletions

File tree

rules-tests/Symfony73/Rector/Class_/GetFiltersToAsTwigFilterAttributeRector/Fixture/some_get_filters.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use Twig\Extension\AbstractExtension;
2929

3030
final class SomeGetFilter
3131
{
32-
#[\Twig\Attribute\AsTwigFilter('some_filter')]
32+
#[\Twig\Attribute\AsTwigFilter(name: 'some_filter')]
3333
public function someFilter($value)
3434
{
3535
return $value;

rules-tests/Symfony73/Rector/Class_/GetFiltersToAsTwigFilterAttributeRector/Fixture/with_first_class_callable_filter.php.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ use Twig\Extension\AbstractExtension;
4141

4242
final class WithFirstClassCallableFilter
4343
{
44-
#[\Twig\Attribute\AsTwigFilter('some_filter')]
44+
#[\Twig\Attribute\AsTwigFilter(name: 'some_filter')]
4545
public function someFilter($value)
4646
{
4747
return $value;
4848
}
4949

50-
#[\Twig\Attribute\AsTwigFilter('another_filter')]
50+
#[\Twig\Attribute\AsTwigFilter(name: 'another_filter')]
5151
public function anotherFilter($value)
5252
{
5353
return $value;
5454
}
5555

56-
#[\Twig\Attribute\AsTwigFilter('third_filter')]
56+
#[\Twig\Attribute\AsTwigFilter(name: 'third_filter')]
5757
public function thirdFilter($value)
5858
{
5959
return $value;

rules-tests/Symfony73/Rector/Class_/GetFiltersToAsTwigFilterAttributeRector/Fixture/with_options_argument.php.inc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,49 +82,49 @@ use Twig\Extension\AbstractExtension;
8282

8383
final class WithOptionsParameter
8484
{
85-
#[\Twig\Attribute\AsTwigFilter('with_environment', needsEnvironment: true)]
85+
#[\Twig\Attribute\AsTwigFilter(name: 'with_environment', needsEnvironment: true)]
8686
public function withEnvironment(Environment $env, $value)
8787
{
8888
return $value;
8989
}
9090

91-
#[\Twig\Attribute\AsTwigFilter('with_context', needsContext: true)]
91+
#[\Twig\Attribute\AsTwigFilter(name: 'with_context', needsContext: true)]
9292
public function withContext(array $context, $value)
9393
{
9494
return $value;
9595
}
9696

97-
#[\Twig\Attribute\AsTwigFilter('with_charset', needsCharset: true)]
97+
#[\Twig\Attribute\AsTwigFilter(name: 'with_charset', needsCharset: true)]
9898
public function withCharset(string $charset, $value)
9999
{
100100
return $value;
101101
}
102102

103-
#[\Twig\Attribute\AsTwigFilter('with_pre_escape', preEscape: 'html')]
103+
#[\Twig\Attribute\AsTwigFilter(name: 'with_pre_escape', preEscape: 'html')]
104104
public function withPreEscape($value)
105105
{
106106
return $value;
107107
}
108108

109-
#[\Twig\Attribute\AsTwigFilter('with_preserves_safety', preservesSafety: ['html'])]
109+
#[\Twig\Attribute\AsTwigFilter(name: 'with_preserves_safety', preservesSafety: ['html'])]
110110
public function withPreservesSafety($value)
111111
{
112112
return $value;
113113
}
114114

115-
#[\Twig\Attribute\AsTwigFilter('with_safe_callback', isSafeCallback: [self::class, 'checkSafeCallback'])]
115+
#[\Twig\Attribute\AsTwigFilter(name: 'with_safe_callback', isSafeCallback: [self::class, 'checkSafeCallback'])]
116116
public function withSafeCallback($value)
117117
{
118118
return $value;
119119
}
120120

121-
#[\Twig\Attribute\AsTwigFilter('with_deprecation_info', deprecationInfo: new DeprecatedCallableInfo('package', 'version'))]
121+
#[\Twig\Attribute\AsTwigFilter(name: 'with_deprecation_info', deprecationInfo: new DeprecatedCallableInfo('package', 'version'))]
122122
public function withDeprecationInfo($value)
123123
{
124124
return $value;
125125
}
126126

127-
#[\Twig\Attribute\AsTwigFilter('with_everything', isSafe: ['html'], needsContext: true, needsCharset: true, needsEnvironment: true, preEscape: 'html', preservesSafety: ['html'])]
127+
#[\Twig\Attribute\AsTwigFilter(name: 'with_everything', isSafe: ['html'], needsContext: true, needsCharset: true, needsEnvironment: true, preEscape: 'html', preservesSafety: ['html'])]
128128
public function withEverything(string $charset, Environment $env, array $context, $value)
129129
{
130130
return $value;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ use Twig\Extension\AbstractExtension;
4141

4242
final class SomeGetFunctions
4343
{
44-
#[\Twig\Attribute\AsTwigFunction('some_function')]
44+
#[\Twig\Attribute\AsTwigFunction(name: 'some_function')]
4545
public function someFunction($value)
4646
{
4747
return $value;
4848
}
4949

50-
#[\Twig\Attribute\AsTwigFunction('another_function')]
50+
#[\Twig\Attribute\AsTwigFunction(name: 'another_function')]
5151
public function anotherFunction($value)
5252
{
5353
return $value;
5454
}
5555

56-
#[\Twig\Attribute\AsTwigFunction('third_function')]
56+
#[\Twig\Attribute\AsTwigFunction(name: 'third_function')]
5757
public function thirdFunction($value)
5858
{
5959
return $value;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,37 @@ use Twig\Extension\AbstractExtension;
7070

7171
final class WithOptionsParameter
7272
{
73-
#[\Twig\Attribute\AsTwigFunction('with_environment', needsEnvironment: true)]
73+
#[\Twig\Attribute\AsTwigFunction(name: 'with_environment', needsEnvironment: true)]
7474
public function withEnvironment(Environment $env, $value)
7575
{
7676
return $value;
7777
}
7878

79-
#[\Twig\Attribute\AsTwigFunction('with_context', needsContext: true)]
79+
#[\Twig\Attribute\AsTwigFunction(name: 'with_context', needsContext: true)]
8080
public function withContext(array $context, $value)
8181
{
8282
return $value;
8383
}
8484

85-
#[\Twig\Attribute\AsTwigFunction('with_charset', needsCharset: true)]
85+
#[\Twig\Attribute\AsTwigFunction(name: 'with_charset', needsCharset: true)]
8686
public function withCharset(string $charset, $value)
8787
{
8888
return $value;
8989
}
9090

91-
#[\Twig\Attribute\AsTwigFunction('with_safe_callback', isSafeCallback: [self::class, 'checkSafeCallback'])]
91+
#[\Twig\Attribute\AsTwigFunction(name: 'with_safe_callback', isSafeCallback: [self::class, 'checkSafeCallback'])]
9292
public function withSafeCallback($value)
9393
{
9494
return $value;
9595
}
9696

97-
#[\Twig\Attribute\AsTwigFunction('with_deprecation_info', deprecationInfo: new DeprecatedCallableInfo('package', 'version'))]
97+
#[\Twig\Attribute\AsTwigFunction(name: 'with_deprecation_info', deprecationInfo: new DeprecatedCallableInfo('package', 'version'))]
9898
public function withDeprecationInfo($value)
9999
{
100100
return $value;
101101
}
102102

103-
#[\Twig\Attribute\AsTwigFunction('with_everything', isSafe: ['html'], needsContext: true, needsCharset: true, needsEnvironment: true)]
103+
#[\Twig\Attribute\AsTwigFunction(name: 'with_everything', isSafe: ['html'], needsContext: true, needsCharset: true, needsEnvironment: true)]
104104
public function withEverything(string $charset, Environment $env, array $context, $value)
105105
{
106106
return $value;

rules/Symfony73/GetMethodToAsTwigAttributeTransformer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public function transformClassGetMethodToAttributeMarker(
127127
// remove old new function instance
128128
unset($returnArray->items[$key]);
129129

130+
$nameArg->name = new Identifier('name');
131+
130132
$hasChanged = true;
131133
}
132134
}

rules/Symfony73/Rector/Class_/GetFunctionsToAsTwigFunctionAttributeRector.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ public function localMethod(Environment $env, $value)
5252
CODE_SAMPLE
5353
,
5454
<<<'CODE_SAMPLE'
55-
use Twig\Extension\AbstractExtension;
5655
use Twig\Attribute\AsTwigFunction;
5756
use Twig\Environment;
5857
59-
class SomeClass extends AbstractExtension
58+
class SomeClass
6059
{
61-
#[AsTwigFunction('function_name', needsEnvironment: true)]
60+
#[AsTwigFunction(name: 'function_name', needsEnvironment: true)]
6261
public function localMethod(Environment $env, $value)
6362
{
6463
return $value;

0 commit comments

Comments
 (0)