Skip to content

Commit 23bcfa6

Browse files
committed
Improve code
Signed-off-by: Liviu-Mihail Concioiu <[email protected]>
1 parent d0a6f78 commit 23bcfa6

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/TokenParser/TransTokenParser.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
use Twig\Token;
2424
use Twig\TokenParser\AbstractTokenParser;
2525

26+
use function method_exists;
27+
2628
class TransTokenParser extends AbstractTokenParser
2729
{
2830
/**
@@ -57,18 +59,24 @@ protected function preParse(Token $token): array
5759
/* If we aren't closing the block, do we have a domain? */
5860
if ($stream->test(Token::NAME_TYPE)) {
5961
$stream->expect(Token::NAME_TYPE, 'from');
60-
$domain = $this->parser->parseExpression();
62+
$domain = method_exists($this->parser, 'parseExpression')
63+
? $this->parser->parseExpression()
64+
: $this->parser->getExpressionParser()->parseExpression();
6165
}
6266

6367
if (! $stream->test(Token::BLOCK_END_TYPE)) {
64-
$body = $this->parser->parseExpression();
68+
$body = method_exists($this->parser, 'parseExpression')
69+
? $this->parser->parseExpression()
70+
: $this->parser->getExpressionParser()->parseExpression();
6571
} else {
6672
$stream->expect(Token::BLOCK_END_TYPE);
6773
$body = $this->parser->subparse([$this, 'decideForFork']);
6874
$next = $stream->next()->getValue();
6975

7076
if ($next === 'plural') {
71-
$count = $this->parser->parseExpression();
77+
$count = method_exists($this->parser, 'parseExpression')
78+
? $this->parser->parseExpression()
79+
: $this->parser->getExpressionParser()->parseExpression();
7280
$stream->expect(Token::BLOCK_END_TYPE);
7381
$plural = $this->parser->subparse([$this, 'decideForFork']);
7482
$next = $stream->next()->getValue();

0 commit comments

Comments
 (0)