Skip to content

Commit c5d58cf

Browse files
axiNyholm
authored andcommitted
Call to trans with variable must not trigger Exception (#147)
1 parent 439717d commit c5d58cf

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Visitor/Php/Symfony/ContainerAwareTrans.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public function enterNode(Node $node): ?Node
4545
//If $this->get('translator')->trans('foobar')
4646
if ('trans' === $name) {
4747
$label = $this->getStringArgument($node, 0);
48+
if (null === $label) {
49+
return null;
50+
}
4851
$domain = $this->getStringArgument($node, 2);
4952

5053
$this->addLocation($label, $node->getAttribute('startLine'), $node, ['domain' => $domain]);

tests/Resources/Php/Symfony/ContainerAwareTrans.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,12 @@ public function static()
5555
{
5656
$translator = static::$container->get('translator'); $foo = $translator->trans('bar');
5757
}
58+
59+
public function transWithVariable()
60+
{
61+
$key = 'trans_key';
62+
63+
// This should not be source Locations
64+
return $this->translator->trans($key);
65+
}
5866
}

0 commit comments

Comments
 (0)