Skip to content

Commit 8987e78

Browse files
committed
Make library fully compatible with Twig 3.21
1 parent 5283b9a commit 8987e78

File tree

6 files changed

+34
-27
lines changed

6 files changed

+34
-27
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
}
1818
],
1919
"require": {
20-
"php": ">=8.0.2",
21-
"twig/twig": "^3.19"
20+
"php": ">=8.1",
21+
"twig/twig": "^3.21"
2222
},
2323
"require-dev": {
2424
"captainhook/captainhook-phar": "^5.0",
@@ -56,7 +56,7 @@
5656
"psalm": "vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --show-info=false",
5757
"psalm_full": "vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --clear-cache && vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --show-info=false",
5858
"psalm_base": "vendor-bin/psalm/vendor/bin/psalm --config=tools/psalm.xml --set-baseline=tools/psalm-baseline.xml",
59-
"phpunit": "vendor/bin/phpunit --configuration=tools/phpunit.xml.dist --colors=always",
59+
"phpunit": "vendor/bin/phpunit --configuration=tools/phpunit.xml.dist --colors=always --verbose",
6060
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --configuration=tools/phpunit.xml.dist --coverage-html=tests/_reports",
6161
"phpcs": "vendor-bin/phpcs/vendor/bin/phpcs --standard=tools/ruleset.xml --extensions=php --cache=tools/cache/.phpcs-cache --colors src tests",
6262
"phpcs_diff": "vendor-bin/phpcs/vendor/bin/phpcs -s --standard=tools/ruleset.xml --extensions=php --cache=tools/cache/.phpcs-cache --colors src tests",

docker/compose/composer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
composer:
3-
image: thecodingmachine/php:8.0-v4-cli
3+
image: thecodingmachine/php:8.1-v4-cli
44
container_name: squirrel_composer
55
working_dir: /usr/src/app
66
command: [ "composer", "${COMPOSER_COMMAND}", "--ansi" ]

src/PhpSyntaxExtension.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Squirrel\TwigPhpSyntax\TokenParser\BreakTokenParser;
1818
use Squirrel\TwigPhpSyntax\TokenParser\ContinueTokenParser;
1919
use Squirrel\TwigPhpSyntax\TokenParser\ForeachTokenParser;
20-
use Twig\ExpressionParser;
20+
use Twig\ExpressionParser\Infix\BinaryOperatorExpressionParser;
2121
use Twig\Extension\AbstractExtension;
2222
use Twig\Node\Expression\Binary\AndBinary;
2323
use Twig\Node\Expression\Binary\OrBinary;
@@ -131,21 +131,13 @@ public function getTests(): array
131131
];
132132
}
133133

134-
public function getOperators(): array
134+
public function getExpressionParsers(): array
135135
{
136136
return [
137-
[
138-
],
139-
[
140-
// instead of "or" the PHP operator "||" does the same
141-
'||' => ['precedence' => 10, 'class' => OrBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
142-
// instead of "and" the PHP operator "&&" does the same
143-
'&&' => ['precedence' => 15, 'class' => AndBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
144-
// instead of "is same as(expression)" it becomes "=== expression"
145-
'===' => ['precedence' => 20, 'class' => SameAsBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
146-
// instead of "is not same as(expression)" it becomes "!== expression"
147-
'!==' => ['precedence' => 20, 'class' => NotSameAsBinary::class, 'associativity' => ExpressionParser::OPERATOR_LEFT],
148-
],
137+
new BinaryOperatorExpressionParser(OrBinary::class, '||', 10),
138+
new BinaryOperatorExpressionParser(AndBinary::class, '&&', 15),
139+
new BinaryOperatorExpressionParser(SameAsBinary::class, '===', 20),
140+
new BinaryOperatorExpressionParser(NotSameAsBinary::class, '!==', 20),
149141
];
150142
}
151143
}

src/TokenParser/ForeachTokenParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function parse(Token $token): Node
2020
{
2121
$lineno = $token->getLine();
2222
$stream = $this->parser->getStream();
23-
$seq = $this->parser->getExpressionParser()->parseExpression();
23+
$seq = $this->parser->parseExpression();
2424
$stream->expect(Token::NAME_TYPE, 'as');
2525
$targets = $this->parseAssignmentExpression();
2626

@@ -81,7 +81,7 @@ protected function parseAssignmentExpression(): Nodes
8181
$targets[] = new AssignContextVariable($token->getValue(), $token->getLine());
8282

8383
// The following line is the only change in the whole method: use => instead of ,
84-
if (!$stream->nextIf(Token::ARROW_TYPE, '=>')) {
84+
if (!$stream->nextIf(Token::OPERATOR_TYPE, '=>')) {
8585
break;
8686
}
8787
}

tools/phpstan-baseline.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?php declare(strict_types = 1);
22

33
$ignoreErrors = [];
4+
$ignoreErrors[] = [
5+
'message' => '#^Method Squirrel\\\\TwigPhpSyntax\\\\PhpSyntaxExtension\\:\\:getExpressionParsers\\(\\) return type has no value type specified in iterable type array\\.$#',
6+
'identifier' => 'missingType.iterableValue',
7+
'count' => 1,
8+
'path' => __DIR__ . '/../src/PhpSyntaxExtension.php',
9+
];
410
$ignoreErrors[] = [
511
'message' => '#^Method Squirrel\\\\TwigPhpSyntax\\\\PhpSyntaxExtension\\:\\:validateType\\(\\) should return bool\\|float\\|int\\|string\\|null but returns mixed\\.$#',
612
'identifier' => 'return.type',
@@ -25,11 +31,5 @@
2531
'count' => 1,
2632
'path' => __DIR__ . '/../src/TokenParser/ForeachTokenParser.php',
2733
];
28-
$ignoreErrors[] = [
29-
'message' => '#^Parameter \\#3 \\$seq of class Twig\\\\Node\\\\ForNode constructor expects Twig\\\\Node\\\\Expression\\\\AbstractExpression, mixed given\\.$#',
30-
'identifier' => 'argument.type',
31-
'count' => 1,
32-
'path' => __DIR__ . '/../src/TokenParser/ForeachTokenParser.php',
33-
];
3434

3535
return ['parameters' => ['ignoreErrors' => $ignoreErrors]];

tools/psalm-baseline.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0"/>
2+
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
3+
<file src="src/PhpSyntaxExtension.php">
4+
<InternalClass>
5+
<code><![CDATA[new BinaryOperatorExpressionParser(AndBinary::class, '&&', 15)]]></code>
6+
<code><![CDATA[new BinaryOperatorExpressionParser(NotSameAsBinary::class, '!==', 20)]]></code>
7+
<code><![CDATA[new BinaryOperatorExpressionParser(OrBinary::class, '||', 10)]]></code>
8+
<code><![CDATA[new BinaryOperatorExpressionParser(SameAsBinary::class, '===', 20)]]></code>
9+
</InternalClass>
10+
<InternalMethod>
11+
<code><![CDATA[new BinaryOperatorExpressionParser(AndBinary::class, '&&', 15)]]></code>
12+
<code><![CDATA[new BinaryOperatorExpressionParser(NotSameAsBinary::class, '!==', 20)]]></code>
13+
<code><![CDATA[new BinaryOperatorExpressionParser(OrBinary::class, '||', 10)]]></code>
14+
<code><![CDATA[new BinaryOperatorExpressionParser(SameAsBinary::class, '===', 20)]]></code>
15+
</InternalMethod>
16+
</file>
17+
</files>

0 commit comments

Comments
 (0)