Skip to content

Commit 00185dd

Browse files
committed
Fix Twig 3.21 deprecation
1 parent 175b036 commit 00185dd

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

phpstan-baseline.neon

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ parameters:
3030
count: 1
3131
path: src/Twig/Extension/QrCodeExtension.php
3232

33+
-
34+
message: """
35+
#^Call to deprecated method getExpressionParser\\(\\) of class Twig\\\\Parser\\:
36+
since Twig 3\\.21$#
37+
"""
38+
count: 3
39+
path: src/Twig/TokenParser/DatalistThemeTokenParser.php
40+
41+
-
42+
message: "#^Call to function method_exists\\(\\) with Twig\\\\Parser and 'parseExpression' will always evaluate to true\\.$#"
43+
count: 3
44+
path: src/Twig/TokenParser/DatalistThemeTokenParser.php
45+
46+
-
47+
message: """
48+
#^Call to deprecated method getExpressionParser\\(\\) of class Twig\\\\Parser\\:
49+
since Twig 3\\.21$#
50+
"""
51+
count: 3
52+
path: src/Twig/TokenParser/PaginatorThemeTokenParser.php
53+
54+
-
55+
message: "#^Call to function method_exists\\(\\) with Twig\\\\Parser and 'parseExpression' will always evaluate to true\\.$#"
56+
count: 3
57+
path: src/Twig/TokenParser/PaginatorThemeTokenParser.php
58+
3359
-
3460
message: "#^Method Leapt\\\\CoreBundle\\\\Tests\\\\LeaptCoreTestingKernel\\:\\:configureContainer\\(\\) is unused\\.$#"
3561
count: 1

src/Twig/TokenParser/DatalistThemeTokenParser.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,30 @@ public function parse(Token $token): DatalistThemeNode
1616
$lineno = $token->getLine();
1717
$stream = $this->parser->getStream();
1818

19-
$datalist = $this->parser->getExpressionParser()->parseExpression();
19+
if (method_exists($this->parser, 'parseExpression')) {
20+
// Since Twig 3.21
21+
$datalist = $this->parser->parseExpression();
22+
} else {
23+
$datalist = $this->parser->getExpressionParser()->parseExpression();
24+
}
2025

2126
if ($this->parser->getStream()->test(Token::NAME_TYPE, 'with')) {
2227
$this->parser->getStream()->next();
23-
$resources = $this->parser->getExpressionParser()->parseExpression();
28+
if (method_exists($this->parser, 'parseExpression')) {
29+
// Since Twig 3.21
30+
$resources = $this->parser->parseExpression();
31+
} else {
32+
$resources = $this->parser->getExpressionParser()->parseExpression();
33+
}
2434
} else {
2535
$resources = new ArrayExpression([], $stream->getCurrent()->getLine());
2636
do {
27-
$resources->addElement($this->parser->getExpressionParser()->parseExpression());
37+
if (method_exists($this->parser, 'parseExpression')) {
38+
// Since Twig 3.21
39+
$resources->addElement($this->parser->parseExpression());
40+
} else {
41+
$resources->addElement($this->parser->getExpressionParser()->parseExpression());
42+
}
2843
} while (!$stream->test(Token::BLOCK_END_TYPE));
2944
}
3045

src/Twig/TokenParser/PaginatorThemeTokenParser.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,30 @@ public function parse(Token $token): PaginatorThemeNode
1616
$lineno = $token->getLine();
1717
$stream = $this->parser->getStream();
1818

19-
$paginator = $this->parser->getExpressionParser()->parseExpression();
19+
if (method_exists($this->parser, 'parseExpression')) {
20+
// Since Twig 3.21
21+
$paginator = $this->parser->parseExpression();
22+
} else {
23+
$paginator = $this->parser->getExpressionParser()->parseExpression();
24+
}
2025

2126
if ($this->parser->getStream()->test(Token::NAME_TYPE, 'with')) {
2227
$this->parser->getStream()->next();
23-
$resources = $this->parser->getExpressionParser()->parseExpression();
28+
if (method_exists($this->parser, 'parseExpression')) {
29+
// Since Twig 3.21
30+
$resources = $this->parser->parseExpression();
31+
} else {
32+
$resources = $this->parser->getExpressionParser()->parseExpression();
33+
}
2434
} else {
2535
$resources = new ArrayExpression([], $stream->getCurrent()->getLine());
2636
do {
27-
$resources->addElement($this->parser->getExpressionParser()->parseExpression());
37+
if (method_exists($this->parser, 'parseExpression')) {
38+
// Since Twig 3.21
39+
$resources->addElement($this->parser->parseExpression());
40+
} else {
41+
$resources->addElement($this->parser->getExpressionParser()->parseExpression());
42+
}
2843
} while (!$stream->test(Token::BLOCK_END_TYPE));
2944
}
3045

0 commit comments

Comments
 (0)