From 7f2c45ac0cf7bec0dbea7d4bce65db9df463ed70 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 7 Oct 2023 17:39:50 +0200 Subject: [PATCH] Remove obsolete code --- .../Tests/Fixtures/format_date.test | 6 +++++ .../Tests/Fixtures/format_date_php8.test | 12 --------- src/Cache/FilesystemCache.php | 2 +- src/Environment.php | 4 +-- src/Node/Expression/ArrayExpression.php | 27 +------------------ src/Node/Expression/CallExpression.php | 6 ++--- .../NodeVisitor/ProfilerNodeVisitor.php | 2 +- src/Test/IntegrationTestCase.php | 2 +- tests/Cache/FilesystemTest.php | 3 +-- .../functions/template_from_string_error.test | 2 -- .../template_from_string_error_php80.test | 10 ------- tests/Node/Expression/CallTest.php | 13 --------- tests/Node/Expression/GetAttrTest.php | 4 +-- tests/TemplateTest.php | 8 ------ 14 files changed, 17 insertions(+), 84 deletions(-) delete mode 100644 extra/intl-extra/Tests/Fixtures/format_date_php8.test delete mode 100644 tests/Fixtures/functions/template_from_string_error_php80.test diff --git a/extra/intl-extra/Tests/Fixtures/format_date.test b/extra/intl-extra/Tests/Fixtures/format_date.test index 75844e1e4bb..afddd083a21 100644 --- a/extra/intl-extra/Tests/Fixtures/format_date.test +++ b/extra/intl-extra/Tests/Fixtures/format_date.test @@ -11,6 +11,9 @@ {{ '2019-08-07 23:39:12'|format_date }} {{ '2019-08-07 23:39:12'|format_date(locale='fr') }} {{ '2019-08-07 23:39:12'|format_time }} + +{{ 'today 23:39:12'|format_datetime('relative_short', 'none', locale='fr') }} +{{ 'today 23:39:12'|format_datetime('relative_full', 'full', locale='fr') }} --DATA-- return []; --EXPECT-- @@ -24,3 +27,6 @@ mercredi 7 août 2019 à 23:39:12 temps universel coordonné Aug 7, 2019 7 août 2019 11:39:12 PM + +aujourd’hui +aujourd’hui à 23:39:12 temps universel coordonné diff --git a/extra/intl-extra/Tests/Fixtures/format_date_php8.test b/extra/intl-extra/Tests/Fixtures/format_date_php8.test deleted file mode 100644 index 67e0e6f4dbe..00000000000 --- a/extra/intl-extra/Tests/Fixtures/format_date_php8.test +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -"format_date" filter ---CONDITION-- -PHP_VERSION_ID >= 80000 ---TEMPLATE-- -{{ 'today 23:39:12'|format_datetime('relative_short', 'none', locale='fr') }} -{{ 'today 23:39:12'|format_datetime('relative_full', 'full', locale='fr') }} ---DATA-- -return []; ---EXPECT-- -aujourd’hui -aujourd’hui à 23:39:12 temps universel coordonné diff --git a/src/Cache/FilesystemCache.php b/src/Cache/FilesystemCache.php index 4024adbd70d..f6bc7afc164 100644 --- a/src/Cache/FilesystemCache.php +++ b/src/Cache/FilesystemCache.php @@ -31,7 +31,7 @@ public function __construct(string $directory, int $options = 0) public function generateKey(string $name, string $className): string { - $hash = hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $className); + $hash = hash('xxh128', $className); return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php'; } diff --git a/src/Environment.php b/src/Environment.php index f55d110583d..fa7771333d7 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -263,7 +263,7 @@ public function getTemplateClass(string $name, int $index = null): string { $key = $this->getLoader()->getCacheKey($name).$this->optionsHash; - return $this->templateClassPrefix.hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $key).(null === $index ? '' : '___'.$index); + return $this->templateClassPrefix.hash('xxh128', $key).(null === $index ? '' : '___'.$index); } /** @@ -384,7 +384,7 @@ public function loadTemplate(string $cls, string $name, int $index = null): Temp */ public function createTemplate(string $template, string $name = null): TemplateWrapper { - $hash = hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $template, false); + $hash = hash('xxh128', $template, false); if (null !== $name) { $name = sprintf('%s (string template %s)', $name, $hash); } else { diff --git a/src/Node/Expression/ArrayExpression.php b/src/Node/Expression/ArrayExpression.php index 44428380239..a9674e28b21 100644 --- a/src/Node/Expression/ArrayExpression.php +++ b/src/Node/Expression/ArrayExpression.php @@ -67,11 +67,6 @@ public function addElement(AbstractExpression $value, AbstractExpression $key = public function compile(Compiler $compiler): void { $keyValuePairs = $this->getKeyValuePairs(); - $needsArrayMergeSpread = \PHP_VERSION_ID < 80100 && $this->hasSpreadItem($keyValuePairs); - - if ($needsArrayMergeSpread) { - $compiler->raw('twig_array_merge('); - } $compiler->raw('['); $first = true; $reopenAfterMergeSpread = false; @@ -82,18 +77,12 @@ public function compile(Compiler $compiler): void $reopenAfterMergeSpread = false; } - if ($needsArrayMergeSpread && $pair['value']->hasAttribute('spread')) { - $compiler->raw('], ')->subcompile($pair['value']); - $first = true; - $reopenAfterMergeSpread = true; - continue; - } if (!$first) { $compiler->raw(', '); } $first = false; - if ($pair['value']->hasAttribute('spread') && !$needsArrayMergeSpread) { + if ($pair['value']->hasAttribute('spread')) { $compiler->raw('...')->subcompile($pair['value']); ++$nextIndex; } else { @@ -117,19 +106,5 @@ public function compile(Compiler $compiler): void if (!$reopenAfterMergeSpread) { $compiler->raw(']'); } - if ($needsArrayMergeSpread) { - $compiler->raw(')'); - } - } - - private function hasSpreadItem(array $pairs): bool - { - foreach ($pairs as $pair) { - if ($pair['value']->hasAttribute('spread')) { - return true; - } - } - - return false; } } diff --git a/src/Node/Expression/CallExpression.php b/src/Node/Expression/CallExpression.php index 3a2d7a4fca4..2ecc031dc9e 100644 --- a/src/Node/Expression/CallExpression.php +++ b/src/Node/Expression/CallExpression.php @@ -148,7 +148,7 @@ protected function getArguments($callable, $arguments) $pos = 0; foreach ($callableParameters as $callableParameter) { $name = $this->normalizeName($callableParameter->name); - if (\PHP_VERSION_ID >= 80000 && 'range' === $callable) { + if ('range' === $callable) { if ('start' === $name) { $name = 'low'; } elseif ('end' === $name) { @@ -304,10 +304,8 @@ private function reflectCallable($callable) if ($object = $r->getClosureThis()) { $callable = [$object, $r->name]; $callableName = get_debug_type($object).'::'.$r->name; - } elseif (\PHP_VERSION_ID >= 80111 && $class = $r->getClosureCalledClass()) { + } elseif ($class = $r->getClosureCalledClass()) { $callableName = $class->name.'::'.$r->name; - } elseif (\PHP_VERSION_ID < 80111 && $class = $r->getClosureScopeClass()) { - $callableName = (\is_array($callable) ? $callable[0] : $class->name).'::'.$r->name; } else { $callable = $callableName = $r->name; } diff --git a/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php b/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php index 91abee807df..e4df09f1d32 100644 --- a/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php +++ b/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php @@ -33,7 +33,7 @@ final class ProfilerNodeVisitor implements NodeVisitorInterface public function __construct(string $extensionName) { $this->extensionName = $extensionName; - $this->varName = sprintf('__internal_%s', hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', $extensionName)); + $this->varName = sprintf('__internal_%s', hash('xxh128', $extensionName)); } public function enterNode(Node $node, Environment $env): Node diff --git a/src/Test/IntegrationTestCase.php b/src/Test/IntegrationTestCase.php index e97ad417062..3830403dbe3 100644 --- a/src/Test/IntegrationTestCase.php +++ b/src/Test/IntegrationTestCase.php @@ -187,7 +187,7 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e // avoid using the same PHP class name for different cases $p = new \ReflectionProperty($twig, 'templateClassPrefix'); $p->setAccessible(true); - $p->setValue($twig, '__TwigTemplate_'.hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', uniqid(mt_rand(), true), false).'_'); + $p->setValue($twig, '__TwigTemplate_'.hash('xxh128', uniqid(mt_rand(), true), false).'_'); $deprecations = []; try { diff --git a/tests/Cache/FilesystemTest.php b/tests/Cache/FilesystemTest.php index 349869c26e3..d26bd7d9f70 100644 --- a/tests/Cache/FilesystemTest.php +++ b/tests/Cache/FilesystemTest.php @@ -23,8 +23,7 @@ class FilesystemTest extends TestCase protected function setUp(): void { - $nonce = hash(\PHP_VERSION_ID < 80100 ? 'sha256' : 'xxh128', uniqid(mt_rand(), true)); - $this->classname = '__Twig_Tests_Cache_FilesystemTest_Template_'.$nonce; + $this->classname = '__Twig_Tests_Cache_FilesystemTest_Template_'.hash('xxh128', uniqid(mt_rand(), true)); $this->directory = sys_get_temp_dir().'/twig-test'; $this->cache = new FilesystemCache($this->directory); } diff --git a/tests/Fixtures/functions/template_from_string_error.test b/tests/Fixtures/functions/template_from_string_error.test index 1132296bc12..43a56b263bf 100644 --- a/tests/Fixtures/functions/template_from_string_error.test +++ b/tests/Fixtures/functions/template_from_string_error.test @@ -1,7 +1,5 @@ --TEST-- "template_from_string" function ---CONDITION-- -PHP_VERSION_ID >= 80100 --TEMPLATE-- {% include template_from_string("{{ not a Twig template ", "foo.twig") %} --DATA-- diff --git a/tests/Fixtures/functions/template_from_string_error_php80.test b/tests/Fixtures/functions/template_from_string_error_php80.test deleted file mode 100644 index 8ebe41f2cda..00000000000 --- a/tests/Fixtures/functions/template_from_string_error_php80.test +++ /dev/null @@ -1,10 +0,0 @@ ---TEST-- -"template_from_string" function ---CONDITION-- -PHP_VERSION_ID < 80100 ---TEMPLATE-- -{% include template_from_string("{{ not a Twig template ", "foo.twig") %} ---DATA-- -return [] ---EXCEPTION-- -Twig\Error\SyntaxError: Unclosed "variable" in "foo.twig (string template 4900163d56b1af4b704c6b0afee7f98ba53418ce7a93d37a3af1882735baf9cd)" at line 1. diff --git a/tests/Node/Expression/CallTest.php b/tests/Node/Expression/CallTest.php index 10fa00bea6e..992eacfcef6 100644 --- a/tests/Node/Expression/CallTest.php +++ b/tests/Node/Expression/CallTest.php @@ -59,19 +59,6 @@ public function testGetArgumentsWithWrongNamedArgumentNames() $this->getArguments($node, ['date', ['Y-m-d', 'timestamp' => null, 'unknown1' => '', 'unknown2' => '']]); } - public function testResolveArgumentsWithMissingValueForOptionalArgument() - { - if (\PHP_VERSION_ID >= 80000) { - $this->markTestSkipped('substr_compare() has a default value in 8.0, so the test does not work anymore, one should find another PHP built-in function for this test to work in PHP 8.'); - } - - $this->expectException(SyntaxError::class); - $this->expectExceptionMessage('Argument "case_sensitivity" could not be assigned for function "substr_compare(main_str, str, offset, length, case_sensitivity)" because it is mapped to an internal PHP function which cannot determine default value for optional argument "length".'); - - $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'substr_compare']); - $this->getArguments($node, ['substr_compare', ['abcd', 'bc', 'offset' => 1, 'case_sensitivity' => true]]); - } - public function testResolveArgumentsOnlyNecessaryArgumentsForCustomFunction() { $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'custom_function']); diff --git a/tests/Node/Expression/GetAttrTest.php b/tests/Node/Expression/GetAttrTest.php index c76fb3992d5..e69f78c80d6 100644 --- a/tests/Node/Expression/GetAttrTest.php +++ b/tests/Node/Expression/GetAttrTest.php @@ -43,7 +43,7 @@ public function getTests() $attr = new ConstantExpression('bar', 1); $args = new ArrayExpression([], 1); $node = new GetAttrExpression($expr, $attr, $args, Template::ANY_CALL, 1); - $tests[] = [$node, sprintf('%s%s, "bar", [], "any", false, false, false, 1)', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))]; + $tests[] = [$node, sprintf('%s%s, "bar", arguments: [], lineno: 1)', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))]; $node = new GetAttrExpression($expr, $attr, $args, Template::ARRAY_CALL, 1); $tests[] = [$node, '(($__internal_%s = // line 1'."\n". @@ -53,7 +53,7 @@ public function getTests() $args->addElement(new NameExpression('foo', 1)); $args->addElement(new ConstantExpression('bar', 1)); $node = new GetAttrExpression($expr, $attr, $args, Template::METHOD_CALL, 1); - $tests[] = [$node, sprintf('%s%s, "bar", [%s, "bar"], "method", false, false, false, 1)', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo'))]; + $tests[] = [$node, sprintf('%s%s, "bar", arguments: [%s, "bar"], type: "method", lineno: 1)', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo'))]; return $tests; } diff --git a/tests/TemplateTest.php b/tests/TemplateTest.php index 9c2364c1d21..de4c1897ace 100644 --- a/tests/TemplateTest.php +++ b/tests/TemplateTest.php @@ -167,15 +167,7 @@ public function testGetAttributeOnArrayWithConfusableKey() $this->assertSame('Zero', $array[false]); $this->assertSame('One', $array[true]); - if (\PHP_VERSION_ID < 80100) { - // This line will trigger a deprecation warning on PHP 8.1. - $this->assertSame('One', $array[1.5]); - } $this->assertSame('One', $array['1']); - if (\PHP_VERSION_ID < 80100) { - // This line will trigger a deprecation warning on PHP 8.1. - $this->assertSame('MinusOne', $array[-1.5]); - } $this->assertSame('FloatButString', $array['1.5']); $this->assertSame('IntegerButStringWithLeadingZeros', $array['01']); $this->assertSame('EmptyString', $array[null]);