diff --git a/rules/Symfony73/Rector/Class_/GetFiltersToAsTwigFilterAttributeRector.php b/rules/Symfony73/Rector/Class_/GetFiltersToAsTwigFilterAttributeRector.php new file mode 100644 index 00000000..dab334d1 --- /dev/null +++ b/rules/Symfony73/Rector/Class_/GetFiltersToAsTwigFilterAttributeRector.php @@ -0,0 +1,85 @@ + true]), + ]; + } + + public function localMethod(Environment $env, $value) + { + return $value; + } +} +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +use Twig\Extension\AbstractExtension; +use Twig\Attribute\AsTwigFilter; +use Twig\Environment; + +class SomeClass extends AbstractExtension +{ + #[AsTwigFilter('filter_name', needsEnvironment: true)] + public function localMethod(Environment $env, $value) + { + return $value; + } +} +CODE_SAMPLE + )] + ); + } + + /** + * @return array> + */ + public function getNodeTypes(): array + { + return [Class_::class]; + } + + /** + * @param Class_ $node + */ + public function refactor(Node $node): ?Class_ + { + throw new ShouldNotHappenException(sprintf( + '"%s" is deprecated, as it converts getFilters() only and leaves getFunctions()/getTests() behind. Use "%s" instead.', + self::class, + GetFiltersAndFunctionsToAsTwigAttributeRector::class + )); + } +} diff --git a/rules/Symfony73/Rector/Class_/GetFunctionsToAsTwigFunctionAttributeRector.php b/rules/Symfony73/Rector/Class_/GetFunctionsToAsTwigFunctionAttributeRector.php new file mode 100644 index 00000000..5a751261 --- /dev/null +++ b/rules/Symfony73/Rector/Class_/GetFunctionsToAsTwigFunctionAttributeRector.php @@ -0,0 +1,85 @@ + true]), + ]; + } + + public function localMethod(Environment $env, $value) + { + return $value; + } +} +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +use Twig\Extension\AbstractExtension; +use Twig\Attribute\AsTwigFunction; +use Twig\Environment; + +class SomeClass extends AbstractExtension +{ + #[AsTwigFunction(name: 'function_name', needsEnvironment: true)] + public function localMethod(Environment $env, $value) + { + return $value; + } +} +CODE_SAMPLE + )] + ); + } + + /** + * @return array> + */ + public function getNodeTypes(): array + { + return [Class_::class]; + } + + /** + * @param Class_ $node + */ + public function refactor(Node $node): ?Class_ + { + throw new ShouldNotHappenException(sprintf( + '"%s" is deprecated, as it converts getFunctions() only and leaves getFilters()/getTests() behind. Use "%s" instead.', + self::class, + GetFiltersAndFunctionsToAsTwigAttributeRector::class + )); + } +}