diff --git a/src/ExpressionParser.php b/src/ExpressionParser.php index 8cd8b194a18..dc4a6015d7b 100644 --- a/src/ExpressionParser.php +++ b/src/ExpressionParser.php @@ -568,7 +568,7 @@ public function parseFilterExpression($node) public function parseFilterExpressionRaw($node) { - if (func_num_args() > 1) { + if (\func_num_args() > 1) { trigger_deprecation('twig/twig', '3.12', 'Passing a second argument to "%s()" is deprecated.', __METHOD__); } diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index 9dc6d6e6a34..ee0a1dbaf47 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -348,7 +348,7 @@ public static function cycle($values, $position): mixed throw new RuntimeError('The "cycle" function expects an array or "ArrayAccess" as first argument.'); } - if (!\is_countable($values)) { + if (!is_countable($values)) { // To be uncommented in 4.0 // throw new RuntimeError('The "cycle" function expects a countable sequence as first argument.'); diff --git a/src/Node/ImportNode.php b/src/Node/ImportNode.php index 31acbe9d19d..9a6033f215b 100644 --- a/src/Node/ImportNode.php +++ b/src/Node/ImportNode.php @@ -29,10 +29,10 @@ class ImportNode extends Node */ public function __construct(AbstractExpression $expr, AbstractExpression $var, int $lineno, $global = true) { - if (null === $global || is_string($global)) { + if (null === $global || \is_string($global)) { trigger_deprecation('twig/twig', '3.12', 'Passing a tag to %s() is deprecated.', __METHOD__); - $global = func_num_args() > 4 ? func_get_arg(4) : true; - } elseif (!is_bool($global)) { + $global = \func_num_args() > 4 ? func_get_arg(4) : true; + } elseif (!\is_bool($global)) { throw new \TypeError(\sprintf('Argument 4 passed to "%s()" must be a boolean, "%s" given.', __METHOD__, get_debug_type($global))); } diff --git a/src/Node/Node.php b/src/Node/Node.php index 38ebdfa8c68..2ccbcf6101f 100644 --- a/src/Node/Node.php +++ b/src/Node/Node.php @@ -47,15 +47,15 @@ public function __construct(array $nodes = [], array $attributes = [], int $line { foreach ($nodes as $name => $node) { if (!$node instanceof self) { - throw new \InvalidArgumentException(\sprintf('Using "%s" for the value of node "%s" of "%s" is not supported. You must pass a \Twig\Node\Node instance.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, static::class)); + throw new \InvalidArgumentException(\sprintf('Using "%s" for the value of node "%s" of "%s" is not supported. You must pass a \Twig\Node\Node instance.', \is_object($node) ? $node::class : (null === $node ? 'null' : \gettype($node)), $name, static::class)); } } $this->nodes = $nodes; $this->attributes = $attributes; $this->lineno = $lineno; - if (func_num_args() > 3) { - trigger_deprecation('twig/twig', '3.12', sprintf('The "tag" constructor argument of the "%s" class is deprecated and ignored (check which TokenParser class set it to "%s"), the tag is now automatically set by the Parser when needed.', static::class, func_get_arg(3) ?: 'null')); + if (\func_num_args() > 3) { + trigger_deprecation('twig/twig', '3.12', \sprintf('The "tag" constructor argument of the "%s" class is deprecated and ignored (check which TokenParser class set it to "%s"), the tag is now automatically set by the Parser when needed.', static::class, func_get_arg(3) ?: 'null')); } } diff --git a/src/Template.php b/src/Template.php index e6bf2486aaf..e8368c5d964 100644 --- a/src/Template.php +++ b/src/Template.php @@ -382,7 +382,7 @@ public function render(array $context): string } /** - * @return iterable + * @return iterable */ public function yield(array $context, array $blocks = []): iterable { @@ -412,7 +412,7 @@ public function yield(array $context, array $blocks = []): iterable } /** - * @return iterable + * @return iterable */ public function yieldBlock($name, array $context, array $blocks = [], $useBlocks = true, ?self $templateContext = null): iterable { @@ -472,7 +472,7 @@ public function yieldBlock($name, array $context, array $blocks = [], $useBlocks * @param array $context The context * @param array $blocks The current set of blocks * - * @return iterable + * @return iterable */ public function yieldParentBlock($name, array $context, array $blocks = []): iterable { @@ -491,7 +491,7 @@ public function yieldParentBlock($name, array $context, array $blocks = []): ite * @param array $context An array of parameters to pass to the template * @param array $blocks An array of blocks to pass to the template * - * @return iterable + * @return iterable */ abstract protected function doDisplay(array $context, array $blocks = []): iterable; } diff --git a/src/Test/NodeTestCase.php b/src/Test/NodeTestCase.php index 09b16ace793..bac0ea6d036 100644 --- a/src/Test/NodeTestCase.php +++ b/src/Test/NodeTestCase.php @@ -118,7 +118,7 @@ final protected static function createAttributeGetter(): string final public static function checkDataProvider(): void { $r = new \ReflectionMethod(static::class, 'getTests'); - if ($r->getDeclaringClass()->getName() !== self::class) { + if (self::class !== $r->getDeclaringClass()->getName()) { trigger_deprecation('twig/twig', '3.13', 'Implementing "%s::getTests()" in "%s" is deprecated, implement "provideTests()" instead.', self::class, static::class); } } diff --git a/src/TokenParser/TypesTokenParser.php b/src/TokenParser/TypesTokenParser.php index b579fd0c04e..2172ed26361 100644 --- a/src/TokenParser/TypesTokenParser.php +++ b/src/TokenParser/TypesTokenParser.php @@ -62,14 +62,14 @@ private function parseSimpleMappingExpression(TokenStream $stream): array $first = false; $nameToken = $stream->expect(Token::NAME_TYPE); - $isOptional = $stream->nextIf(Token::PUNCTUATION_TYPE, '?') !== null; + $isOptional = null !== $stream->nextIf(Token::PUNCTUATION_TYPE, '?'); $stream->expect(Token::PUNCTUATION_TYPE, ':', 'A type name must be followed by a colon (:)'); $valueToken = $stream->expect(Token::STRING_TYPE); $types[$nameToken->getValue()] = [ - 'type' => $valueToken->getValue(), + 'type' => $valueToken->getValue(), 'optional' => $isOptional, ]; } diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php index ff8dc741bc1..5f8d21bb92a 100644 --- a/tests/EnvironmentTest.php +++ b/tests/EnvironmentTest.php @@ -178,7 +178,7 @@ public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate() // force compilation $twig = new Environment($loader = new ArrayLoader(['index' => '{{ foo }}']), $options); - $twig->addExtension($extension = new class extends AbstractExtension { + $twig->addExtension($extension = new class() extends AbstractExtension { public bool $throw = false; public function getFilters(): array diff --git a/tests/Extension/CoreTest.php b/tests/Extension/CoreTest.php index 2272bb4d03c..e869f96c7b5 100644 --- a/tests/Extension/CoreTest.php +++ b/tests/Extension/CoreTest.php @@ -43,7 +43,7 @@ public static function provideCycleCases() /** * @dataProvider provideCycleInvalidCases */ - public function testCycleFunctionThrowRuntimeError($values, mixed $position = null) + public function testCycleFunctionThrowRuntimeError($values, mixed $position = null) { $this->expectException(RuntimeError::class); CoreExtension::cycle($values, $position ?? 0); @@ -53,7 +53,8 @@ public static function provideCycleInvalidCases() { return [ 'empty' => [[]], - 'non-countable' => [new class extends \ArrayObject{}], + 'non-countable' => [new class() extends \ArrayObject { + }], ]; } diff --git a/tests/Extension/SandboxTest.php b/tests/Extension/SandboxTest.php index 70052b859c8..d24a06c6720 100644 --- a/tests/Extension/SandboxTest.php +++ b/tests/Extension/SandboxTest.php @@ -76,7 +76,7 @@ public function testSandboxForCoreTags(string $tag, string $template) $twig = $this->getEnvironment(true, [], self::$templates, []); $this->expectException(SecurityError::class); - $this->expectExceptionMessageMatches(sprintf('/Tag "%s" is not allowed in "index \(string template .+?\)" at line 1/', $tag)); + $this->expectExceptionMessageMatches(\sprintf('/Tag "%s" is not allowed in "index \(string template .+?\)" at line 1/', $tag)); $twig->createTemplate($template, 'index')->render([]); } @@ -90,7 +90,7 @@ public static function getSandboxedForCoreTagsTests() yield ['do', '{% do 1 + 2 %}']; yield ['embed', '{% embed "base.twig" %}{% endembed %}']; // To be uncommented in 4.0 - //yield ['extends', '{% extends "base.twig" %}']; + // yield ['extends', '{% extends "base.twig" %}']; yield ['flush', '{% flush %}']; yield ['for', '{% for i in 1..2 %}{% endfor %}']; yield ['from', '{% from "macros" import foo %}']; @@ -101,7 +101,7 @@ public static function getSandboxedForCoreTagsTests() yield ['sandbox', '{% sandbox %}{% endsandbox %}']; yield ['set', '{% set foo = 1 %}']; // To be uncommented in 4.0 - //yield ['use', '{% use "1_empty" %}']; + // yield ['use', '{% use "1_empty" %}']; yield ['with', '{% with foo %}{% endwith %}']; } @@ -112,7 +112,7 @@ public static function getSandboxedForCoreTagsTests() */ public function testSandboxForExtendsAndUseTags(string $tag, string $template) { - $this->expectDeprecation(sprintf('Since twig/twig 3.12: The "%s" tag is always allowed in sandboxes, but won\'t be in 4.0, please enable it explicitly in your sandbox policy if needed.', $tag)); + $this->expectDeprecation(\sprintf('Since twig/twig 3.12: The "%s" tag is always allowed in sandboxes, but won\'t be in 4.0, please enable it explicitly in your sandbox policy if needed.', $tag)); $twig = $this->getEnvironment(true, [], self::$templates, []); $twig->createTemplate($template, 'index')->render([]); diff --git a/tests/Node/Expression/FilterTest.php b/tests/Node/Expression/FilterTest.php index 1339b07dd46..78bf5066426 100644 --- a/tests/Node/Expression/FilterTest.php +++ b/tests/Node/Expression/FilterTest.php @@ -179,7 +179,7 @@ protected static function createEnvironment(): Environment private static function createExtension(): AbstractExtension { - return new class extends AbstractExtension { + return new class() extends AbstractExtension { public function getFilters(): array { return [ diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 4d61c2341d0..dc45fd66d30 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -197,7 +197,7 @@ public function testImplicitMacroArgumentDefaultValues() $this->assertNull($argumentNodes->getNode('po')->getAttribute('value')); $this->assertFalse($argumentNodes->getNode('lo')->hasAttribute('is_implicit')); - $this->assertSame(true, $argumentNodes->getNode('lo')->getAttribute('value')); + $this->assertTrue($argumentNodes->getNode('lo')->getAttribute('value')); } protected function getParser() diff --git a/tests/TemplateTest.php b/tests/TemplateTest.php index 801701af2cc..7018f4afba8 100644 --- a/tests/TemplateTest.php +++ b/tests/TemplateTest.php @@ -452,12 +452,12 @@ public function getTemplateName(): string return $this->name; } - public function getDebugInfo() : array + public function getDebugInfo(): array { return []; } - public function getSourceContext() : Source + public function getSourceContext(): Source { return new Source('', $this->getTemplateName()); } diff --git a/tests/TokenParser/TypesTokenParserTest.php b/tests/TokenParser/TypesTokenParserTest.php index 57ccb77cb03..85ce6f7a590 100644 --- a/tests/TokenParser/TypesTokenParserTest.php +++ b/tests/TokenParser/TypesTokenParserTest.php @@ -35,7 +35,7 @@ public static function getMappingTests(): array [ '{% types {foo: "bar"} %}', [ - 'foo' => ['type' => 'bar', 'optional' => false] + 'foo' => ['type' => 'bar', 'optional' => false], ], ], @@ -43,7 +43,7 @@ public static function getMappingTests(): array [ '{% types {foo: "bar",} %}', [ - 'foo' => ['type' => 'bar', 'optional' => false] + 'foo' => ['type' => 'bar', 'optional' => false], ], ], @@ -51,7 +51,7 @@ public static function getMappingTests(): array [ '{% types {foo?: "bar"} %}', [ - 'foo' => ['type' => 'bar', 'optional' => true] + 'foo' => ['type' => 'bar', 'optional' => true], ], ], @@ -61,7 +61,7 @@ public static function getMappingTests(): array [ 'foo' => ['type' => 'foo', 'optional' => false], 'bar' => ['type' => 'foo', 'optional' => true], - 'baz' => ['type' => 'baz', 'optional' => false] + 'baz' => ['type' => 'baz', 'optional' => false], ], ], ];