Symfony version(s) affected: ^5.0
Description
Symfony\Bridge\Twig\Extension\TranslationExtension::__construct() has and optional NodeVisitorInterface as a second argument. This argument is stored in the $translationNodeVisitor property which has a getter public function getTranslationNodeVisitor(): TranslationNodeVisitor.
When constructing the TranslationExtension with any NodeVisitorInterface other than TranslationNodeVisitor, you will get a type error when calling getTranslationNodeVisitor()
How to reproduce
$translationExtension = new \Symfony\Bridge\Twig\Extension\TranslationExtension(
null,
new \Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor()
);
$translationExtension->getTranslationNodeVisitor();
Possible Solution
Create a new interface that defines the public TranslationNodeVisitor methods and return that.
interface TranslationNodeVisitorInterface extends NodeVisitorInterface
{
public function enable(): void;
public function disable(): void;
public function getMessages(): array;
}
Additional context