Skip to content

Commit

Permalink
Remove obsolete code
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Dec 9, 2023
1 parent 583d7b2 commit 7f2c45a
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 84 deletions.
6 changes: 6 additions & 0 deletions extra/intl-extra/Tests/Fixtures/format_date.test
Original file line number Diff line number Diff line change
Expand Up @@ -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--
Expand All @@ -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é
12 changes: 0 additions & 12 deletions extra/intl-extra/Tests/Fixtures/format_date_php8.test

This file was deleted.

2 changes: 1 addition & 1 deletion src/Cache/FilesystemCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
4 changes: 2 additions & 2 deletions src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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 {
Expand Down
27 changes: 1 addition & 26 deletions src/Node/Expression/ArrayExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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;
}
}
6 changes: 2 additions & 4 deletions src/Node/Expression/CallExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Profiler/NodeVisitor/ProfilerNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Test/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions tests/Cache/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions tests/Fixtures/functions/template_from_string_error.test
Original file line number Diff line number Diff line change
@@ -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--
Expand Down
10 changes: 0 additions & 10 deletions tests/Fixtures/functions/template_from_string_error_php80.test

This file was deleted.

13 changes: 0 additions & 13 deletions tests/Node/Expression/CallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
4 changes: 2 additions & 2 deletions tests/Node/Expression/GetAttrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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;
}
Expand Down
8 changes: 0 additions & 8 deletions tests/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 7f2c45a

Please sign in to comment.