From a3fa92dd11d20155cc92d8b0ebdf674592b3b61d Mon Sep 17 00:00:00 2001 From: Sergey Danilchenko Date: Wed, 11 Jun 2025 11:51:54 +0200 Subject: [PATCH] Work around deprecated "is_defined_test" attribute --- composer.json | 2 +- src/Node/GetAttrNode.php | 4 ++-- src/NodeVisitor/GetAttrAdjuster.php | 7 +++++-- tests/Node/GetAttrTest.php | 1 - 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index b85fa39..9668b23 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ ], "require": { "php": "^8.1", - "twig/twig": "~3.12", + "twig/twig": "~3.21", "illuminate/support": "^9|^10|^11|^12", "illuminate/view": "^9|^10|^11|^12" }, diff --git a/src/Node/GetAttrNode.php b/src/Node/GetAttrNode.php index 51b22e7..a0eaa1e 100644 --- a/src/Node/GetAttrNode.php +++ b/src/Node/GetAttrNode.php @@ -47,7 +47,7 @@ public function compile(Compiler $compiler): void // optimize array calls if ($this->getAttribute('optimizable') && (!$env->isStrictVariables() || $this->getAttribute('ignore_strict_check')) - && !$this->getAttribute('is_defined_test') + && !$this->isDefinedTestEnabled() && Template::ARRAY_CALL === $this->getAttribute('type') ) { $var = '$'.$compiler->getVarName(); @@ -91,7 +91,7 @@ public function compile(Compiler $compiler): void $compiler->raw(', ') ->repr($this->getAttribute('type')) - ->raw(', ')->repr($this->getAttribute('is_defined_test')) + ->raw(', ')->repr($this->isDefinedTestEnabled()) ->raw(', ')->repr($this->getAttribute('ignore_strict_check')) ->raw(', ')->repr($env->hasExtension(SandboxExtension::class)) ->raw(', ')->repr($this->getNode('node')->getTemplateLine()) diff --git a/src/NodeVisitor/GetAttrAdjuster.php b/src/NodeVisitor/GetAttrAdjuster.php index d601e1b..7114c3c 100644 --- a/src/NodeVisitor/GetAttrAdjuster.php +++ b/src/NodeVisitor/GetAttrAdjuster.php @@ -40,12 +40,15 @@ public function enterNode(Node $node, Environment $env): Node $attributes = [ 'type' => $node->getAttribute('type'), - 'is_defined_test' => $node->getAttribute('is_defined_test'), 'ignore_strict_check' => $node->getAttribute('ignore_strict_check'), 'optimizable' => $node->getAttribute('optimizable'), ]; - return new GetAttrNode($nodes, $attributes, $node->getTemplateLine()); + $newNode = new GetAttrNode($nodes, $attributes, $node->getTemplateLine()); + + $node->isDefinedTestEnabled() && $newNode->enableDefinedTest(); + + return $newNode; } /** diff --git a/tests/Node/GetAttrTest.php b/tests/Node/GetAttrTest.php index 99ac401..bad173e 100644 --- a/tests/Node/GetAttrTest.php +++ b/tests/Node/GetAttrTest.php @@ -157,7 +157,6 @@ protected function getNode($expr, $attr, $args, $type, $lineno = 1) $nodes = ['node' => $expr, 'attribute' => $attr, 'arguments' => $args]; $attributes = [ 'type' => $type, - 'is_defined_test' => false, 'ignore_strict_check' => false, 'optimizable' => true ];