Deprecate NameExpression internal methods

Deprecate two methods from NameExpression:
* isSimple(): did not find any usage in Twig (or even Symfony) repositories
* isSpecial(): inlined for better performance ($name is available in the method)
This commit is contained in:
Simon André
2024-07-22 01:25:30 +02:00
parent 1377f2da4e
commit 3531f959d3
3 changed files with 19 additions and 3 deletions
+3 -1
View File
@@ -5,9 +5,11 @@
* Deprecate the second argument of `Twig\Node\Expression\CallExpression::compileArguments()`
* Deprecate `Twig\ExpressionParser\parseHashExpression()` in favor of
`Twig\ExpressionParser::parseMappingExpression()`
* Deprecate `Twig\ExpressionParser\parseArrayExpression()`` in favor of
* Deprecate `Twig\ExpressionParser\parseArrayExpression()` in favor of
`Twig\ExpressionParser::parseSequenceExpression()`
* Add `sequence` and `mapping` tests
* Deprecate `Twig\Node\Expression\NameExpression::isSimple()` and
`Twig\Node\Expression\NameExpression::isSpecial()`
# 3.10.3 (2024-05-16)
+4
View File
@@ -39,6 +39,10 @@ Nodes
``Twig\Node\Expression\CallExpression::compileArguments()`` method is
deprecated.
* The ``Twig\Node\Expression\NameExpression::isSimple()`` and
``Twig\Node\Expression\NameExpression::isSpecial()`` methods are deprecated as
of Twig 3.11 and will be removed in Twig 4.0.
Node Visitors
-------------
+12 -2
View File
@@ -34,7 +34,7 @@ class NameExpression extends AbstractExpression
$compiler->addDebugInfo($this);
if ($this->getAttribute('is_defined_test')) {
if ($this->isSpecial()) {
if (isset($this->specialVars[$name])) {
$compiler->repr(true);
} elseif (\PHP_VERSION_ID >= 70400) {
$compiler
@@ -51,7 +51,7 @@ class NameExpression extends AbstractExpression
->raw(', $context))')
;
}
} elseif ($this->isSpecial()) {
} elseif (isset($this->specialVars[$name])) {
$compiler->raw($this->specialVars[$name]);
} elseif ($this->getAttribute('always_defined')) {
$compiler
@@ -85,13 +85,23 @@ class NameExpression extends AbstractExpression
}
}
/**
* @deprecated since Twig 3.11 (to be removed in 4.0)
*/
public function isSpecial()
{
trigger_deprecation('twig/twig', '3.11', 'The "%s()" method is deprecated and will be removed in Twig 4.0.', __METHOD__);
return isset($this->specialVars[$this->getAttribute('name')]);
}
/**
* @deprecated since Twig 3.11 (to be removed in 4.0)
*/
public function isSimple()
{
trigger_deprecation('twig/twig', '3.11', 'The "%s()" method is deprecated and will be removed in Twig 4.0.', __METHOD__);
return !$this->isSpecial() && !$this->getAttribute('is_defined_test');
}
}