Skip to content

Commit

Permalink
[Translation] add tests + fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Dec 13, 2022
1 parent 41933e0 commit 3294288
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 2 additions & 8 deletions Extractor/Visitor/AbstractVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,11 @@ protected function getStringArguments(Node\Expr\CallLike|Node\Attribute|Node\Exp

$args = $node instanceof Node\Expr\CallLike ? $node->getRawArgs() : $node->args;

if (\count($args) < $index) {
if (!($arg = $args[$index] ?? null) instanceof Node\Arg) {
return [];
}

if (($arg = $args[$index]) instanceof Node\Arg) {
if ($result = $this->getStringValue($arg->value)) {
return [$result];
}
}

return [];
return (array) $this->getStringValue($arg->value);
}

protected function hasNodeNamedArguments(Node\Expr\CallLike|Node\Attribute|Node\Expr\New_ $node): bool
Expand Down
2 changes: 2 additions & 0 deletions Tests/fixtures/extractor-ast/translation.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@
<?php echo $view['translator']->trans('variable-assignation-inlined-in-trans-method-call3', [], $domain = 'not_messages'); ?>

<?php echo $view['translator']->trans(domain: $domain = 'not_messages', message: $key = 'variable-assignation-inlined-with-named-arguments-in-trans-method', parameters: $parameters = []); ?>

<?php echo $view['translator']->trans(...); // should not fail ?>

0 comments on commit 3294288

Please sign in to comment.