diff --git a/src/Visitor/Php/Symfony/ContainerAwareTrans.php b/src/Visitor/Php/Symfony/ContainerAwareTrans.php index 625d17a..2b07903 100644 --- a/src/Visitor/Php/Symfony/ContainerAwareTrans.php +++ b/src/Visitor/Php/Symfony/ContainerAwareTrans.php @@ -45,6 +45,9 @@ public function enterNode(Node $node): ?Node //If $this->get('translator')->trans('foobar') if ('trans' === $name) { $label = $this->getStringArgument($node, 0); + if (null === $label) { + return null; + } $domain = $this->getStringArgument($node, 2); $this->addLocation($label, $node->getAttribute('startLine'), $node, ['domain' => $domain]); diff --git a/tests/Resources/Php/Symfony/ContainerAwareTrans.php b/tests/Resources/Php/Symfony/ContainerAwareTrans.php index 01bbe8f..9878546 100644 --- a/tests/Resources/Php/Symfony/ContainerAwareTrans.php +++ b/tests/Resources/Php/Symfony/ContainerAwareTrans.php @@ -55,4 +55,12 @@ public function static() { $translator = static::$container->get('translator'); $foo = $translator->trans('bar'); } + + public function transWithVariable() + { + $key = 'trans_key'; + + // This should not be source Locations + return $this->translator->trans($key); + } }