Skip to content

Commit 79fc178

Browse files
committed
Remove === and !== when using Twig >=3.23
Twig provides these operators natively now, so our own implementation is not needed anymore.
1 parent 6cdd734 commit 79fc178

31 files changed

+149
-74
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ Features
5353

5454
Twig has the `same as` test, which mimicks `===` in PHP, but has a syntax that can be hard to get used to. Using the strict comparison operators from PHP (`===` and `!==`) reduces friction, is familiar and less verbose.
5555

56+
Twig >=3.23 implemented `===` and `!==` natively, so this functionality is provided by Twig when using Twig version >=3.23.
57+
5658
```twig
5759
{% if 1 === 1 %}
5860
This will be shown

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
],
1919
"require": {
2020
"php": ">=8.1",
21-
"twig/twig": "^3.21"
21+
"twig/twig": "^3.23"
2222
},
2323
"require-dev": {
2424
"captainhook/captainhook-phar": "^5.0",
2525
"captainhook/hook-installer": "^1.0",
2626
"phpunit/phpunit": "^9.0",
27-
"symfony/finder": "^6.0|^7.0",
28-
"symfony/process": "^6.0|^7.0"
27+
"symfony/finder": "^6.0|^7.0|^8.0",
28+
"symfony/process": "^6.0|^7.0|^8.0"
2929
},
3030
"config": {
3131
"sort-packages": false,

docker/compose/composer.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
services:
22
composer:
3-
image: thecodingmachine/php:8.1-v4-cli
3+
image: thecodingmachine/php:8.4-v5-cli
44
container_name: squirrel_composer
5+
tty: true
56
working_dir: /usr/src/app
67
command: [ "composer", "${COMPOSER_COMMAND}", "--ansi" ]
7-
logging:
8-
driver: "none"
98
volumes:
109
- .:/usr/src/app
1110
- "$HOME/.cache/composer:/tmp/composer_cache"
1211
environment:
13-
COMPOSER_CACHE_DIR: "/tmp/composer_cache"
14-
COMPOSER_ROOT_VERSION: 'dev-master'
1512
# Basic config for CLI commands
1613
PHP_INI_ERROR_REPORTING: "E_ALL"
1714
PHP_INI_MEMORY_LIMIT: "1g"
@@ -21,6 +18,6 @@ services:
2118
PHP_INI_OPCACHE__MEMORY_CONSUMPTION: 256
2219
PHP_INI_OPCACHE__VALIDATE_TIMESTAMPS: 0
2320
PHP_INI_JIT_BUFFER_SIZE: "256m"
24-
# For code coverage
25-
PHP_EXTENSION_XDEBUG: 1
26-
XDEBUG_MODE: coverage
21+
# Composer config to use global cache
22+
COMPOSER_CACHE_DIR: "/tmp/composer_cache"
23+
COMPOSER_ROOT_VERSION: 'dev-master'

docker/compose/coverage.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
coverage:
3+
image: thecodingmachine/php:8.4-v5-cli
4+
container_name: squirrel_coverage
5+
tty: true
6+
working_dir: /usr/src/app
7+
command: [ "vendor/bin/phpunit", "--configuration=tools/phpunit.xml.dist", "--colors=always", "--coverage-html", "tests/_reports"]
8+
volumes:
9+
- .:/usr/src/app
10+
- "$HOME/.cache/composer:/tmp/composer_cache"
11+
environment:
12+
# Basic config for CLI commands
13+
PHP_INI_ERROR_REPORTING: "E_ALL"
14+
PHP_INI_MEMORY_LIMIT: "1g"
15+
PHP_INI_MAX_EXECUTION_TIME: 3600
16+
# Enable Opcache, disable JIT
17+
PHP_INI_OPCACHE__ENABLE_CLI: 1
18+
PHP_INI_OPCACHE__MEMORY_CONSUMPTION: 256
19+
PHP_INI_OPCACHE__VALIDATE_TIMESTAMPS: 0
20+
PHP_INI_OPCACHE__JIT: "disable"
21+
# Composer config to use global cache
22+
COMPOSER_CACHE_DIR: "/tmp/composer_cache"
23+
COMPOSER_ROOT_VERSION: 'dev-master'
24+
# Enable XDEBUG for coverage
25+
PHP_EXTENSION_XDEBUG: 1
26+
XDEBUG_MODE: coverage
27+
#PHP_EXTENSION_PCOV: 1
28+
# Install all composer dependencies before running tests + delete previous coverage report
29+
STARTUP_COMMAND_1: composer --no-interaction --no-progress --no-scripts --no-plugins --quiet install
30+
STARTUP_COMMAND_2: rm -rf /usr/src/app/tests/_reports/*

docker/compose/test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
services:
2+
test:
3+
image: thecodingmachine/php:8.4-v5-cli
4+
container_name: squirrel_test
5+
tty: true
6+
working_dir: /usr/src/app
7+
command: ["vendor/bin/phpunit", "--configuration=tools/phpunit.xml.dist", "--colors=always"]
8+
volumes:
9+
- .:/usr/src/app
10+
- "$HOME/.cache/composer:/tmp/composer_cache"
11+
environment:
12+
# Basic config for CLI commands
13+
PHP_INI_ERROR_REPORTING: "E_ALL"
14+
PHP_INI_MEMORY_LIMIT: "1g"
15+
PHP_INI_MAX_EXECUTION_TIME: 3600
16+
# Enable Opcache, disable JIT
17+
PHP_INI_OPCACHE__ENABLE_CLI: 1
18+
PHP_INI_OPCACHE__MEMORY_CONSUMPTION: 256
19+
PHP_INI_OPCACHE__VALIDATE_TIMESTAMPS: 0
20+
PHP_INI_OPCACHE__JIT: "disable"
21+
# Composer config to use global cache
22+
COMPOSER_CACHE_DIR: "/tmp/composer_cache"
23+
COMPOSER_ROOT_VERSION: 'dev-master'
24+
# Install all composer dependencies before running tests
25+
STARTUP_COMMAND_1: composer --no-interaction --no-progress --no-scripts --no-plugins --quiet install

docker/composer

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
# Get directory of this script
33
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
44

5+
# Remove all running docker containers
6+
COMPOSER_COMMAND="$@" docker compose -f "$DIR/compose/composer.yml" --project-directory "$DIR/.." --project-name=squirrel_composer down --volumes --remove-orphans
7+
8+
# Run composer with given arguments
59
COMPOSER_COMMAND="$@" docker compose -f "$DIR/compose/composer.yml" --project-directory "$DIR/.." --project-name=squirrel_composer up --abort-on-container-exit --exit-code-from=composer --no-log-prefix composer 2>&1

docker/coverage

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
# Get directory of this script
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
5+
# Remove all running docker containers
6+
docker compose -f "$DIR/compose/coverage.yml" --project-directory "$DIR/.." --project-name=squirrel_coverage down --volumes --remove-orphans
7+
8+
# Run tests with coverage report
9+
docker compose -f "$DIR/compose/coverage.yml" --project-directory "$DIR/.." --project-name=squirrel_coverage up --abort-on-container-exit --exit-code-from=coverage coverage
10+
11+
# Remove all running docker containers
12+
docker compose -f "$DIR/compose/coverage.yml" --project-directory "$DIR/.." --project-name=squirrel_coverage down --volumes --remove-orphans

docker/test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
# Get directory of this script
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
4+
5+
# Remove all running docker containers
6+
docker compose -f "$DIR/compose/test.yml" --project-directory "$DIR/.." --project-name=squirrel_test down --volumes --remove-orphans
7+
8+
# Run tests
9+
docker compose -f "$DIR/compose/test.yml" --project-directory "$DIR/.." --project-name=squirrel_test up --abort-on-container-exit --exit-code-from=test test
10+
11+
# Remove all running docker containers
12+
docker compose -f "$DIR/compose/test.yml" --project-directory "$DIR/.." --project-name=squirrel_test down --volumes --remove-orphans

src/ExpressionParser/BinaryOperatorExpressionParser.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,38 @@
1010
use Twig\Parser;
1111
use Twig\Token;
1212

13-
class BinaryOperatorExpressionParser extends AbstractExpressionParser implements InfixExpressionParserInterface
13+
final class BinaryOperatorExpressionParser extends AbstractExpressionParser implements InfixExpressionParserInterface
1414
{
1515
public function __construct(
1616
/** @var class-string<AbstractBinary> $nodeClass */
17-
private string $nodeClass,
18-
private string $name,
19-
private int $precedence,
20-
private InfixAssociativity $associativity = InfixAssociativity::Left,
17+
private readonly string $nodeClass,
18+
private readonly string $name,
19+
private readonly int $precedence,
20+
private readonly InfixAssociativity $associativity = InfixAssociativity::Left,
2121
) {
2222
}
2323

24-
/**
25-
* @return AbstractBinary
26-
*/
27-
public function parse(Parser $parser, AbstractExpression $left, Token $token): AbstractExpression
24+
#[\Override]
25+
public function parse(Parser $parser, AbstractExpression $left, Token $token): AbstractBinary
2826
{
2927
$right = $parser->parseExpression($this->getAssociativity() === InfixAssociativity::Left ? $this->getPrecedence() + 1 : $this->getPrecedence());
3028

3129
return new ($this->nodeClass)($left, $right, $token->getLine());
3230
}
3331

32+
#[\Override]
3433
public function getAssociativity(): InfixAssociativity
3534
{
3635
return $this->associativity;
3736
}
3837

38+
#[\Override]
3939
public function getName(): string
4040
{
4141
return $this->name;
4242
}
4343

44+
#[\Override]
4445
public function getPrecedence(): int
4546
{
4647
return $this->precedence;

src/Operator/NotSameAsBinary.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)