From 9b4ad856cc479b3eb74560ed052405cc562a0fc1 Mon Sep 17 00:00:00 2001 From: Alexis Date: Mon, 13 Jan 2020 11:38:15 +0100 Subject: [PATCH] Call to trans with variable must not trigger Exception --- src/Visitor/Php/Symfony/ContainerAwareTrans.php | 3 +++ tests/Resources/Php/Symfony/ContainerAwareTrans.php | 8 ++++++++ 2 files changed, 11 insertions(+) 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); + } }