Find the best Rector rule to solve your problem. Searching through 1009 rules.
Found 1 rule. That's the one:
Changes getFilters(), getFunctions() and getTests() in TwigExtension to #[AsTwigFilter], #[AsTwigFunction] and #[AsTwigTest] marker attributes above local class methods
-use Twig\Extension\AbstractExtension;
+use Twig\Attribute\AsTwigFilter;
+use Twig\Attribute\AsTwigFunction;
use Twig\Environment;
-class SomeClass extends AbstractExtension
+class SomeClass
{
- public function getFilters()
- {
- return [
- new \Twig\TwigFilter('filter_name', [$this, 'localMethod'], ['needs_environment' => true]),
- ];
- }
-
- public function getFunctions()
- {
- return [
- new \Twig\TwigFunction('function_name', [$this, 'localMethod'], ['needs_environment' => true]),
- ];
- }
-
+ #[AsTwigFilter(name: 'filter_name', needsEnvironment: true)]
+ #[AsTwigFunction(name: 'function_name', needsEnvironment: true)]
public function localMethod(Environment $env, $value)
{
return $value;
}
}