mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
Fix CS
This commit is contained in:
@@ -568,7 +568,7 @@ class ExpressionParser
|
||||
|
||||
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__);
|
||||
}
|
||||
|
||||
|
||||
@@ -348,7 +348,7 @@ final class CoreExtension extends AbstractExtension
|
||||
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.');
|
||||
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -47,15 +47,15 @@ class Node implements \Countable, \IteratorAggregate
|
||||
{
|
||||
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'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -382,7 +382,7 @@ abstract class Template
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<null|scalar|\Stringable>
|
||||
* @return iterable<scalar|\Stringable|null>
|
||||
*/
|
||||
public function yield(array $context, array $blocks = []): iterable
|
||||
{
|
||||
@@ -412,7 +412,7 @@ abstract class Template
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<null|scalar|\Stringable>
|
||||
* @return iterable<scalar|\Stringable|null>
|
||||
*/
|
||||
public function yieldBlock($name, array $context, array $blocks = [], $useBlocks = true, ?self $templateContext = null): iterable
|
||||
{
|
||||
@@ -472,7 +472,7 @@ abstract class Template
|
||||
* @param array $context The context
|
||||
* @param array $blocks The current set of blocks
|
||||
*
|
||||
* @return iterable<null|scalar|\Stringable>
|
||||
* @return iterable<scalar|\Stringable|null>
|
||||
*/
|
||||
public function yieldParentBlock($name, array $context, array $blocks = []): iterable
|
||||
{
|
||||
@@ -491,7 +491,7 @@ abstract class Template
|
||||
* @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<null|scalar|\Stringable>
|
||||
* @return iterable<scalar|\Stringable|null>
|
||||
*/
|
||||
abstract protected function doDisplay(array $context, array $blocks = []): iterable;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ abstract class NodeTestCase extends TestCase
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,14 +62,14 @@ final class TypesTokenParser extends AbstractTokenParser
|
||||
$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,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ class EnvironmentTest extends TestCase
|
||||
|
||||
// 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
|
||||
|
||||
@@ -43,7 +43,7 @@ class CoreTest extends TestCase
|
||||
/**
|
||||
* @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 @@ class CoreTest extends TestCase
|
||||
{
|
||||
return [
|
||||
'empty' => [[]],
|
||||
'non-countable' => [new class extends \ArrayObject{}],
|
||||
'non-countable' => [new class() extends \ArrayObject {
|
||||
}],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ class SandboxTest extends TestCase
|
||||
$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 @@ class SandboxTest extends TestCase
|
||||
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 @@ class SandboxTest extends TestCase
|
||||
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 @@ class SandboxTest extends TestCase
|
||||
*/
|
||||
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([]);
|
||||
|
||||
@@ -179,7 +179,7 @@ class FilterTest extends NodeTestCase
|
||||
|
||||
private static function createExtension(): AbstractExtension
|
||||
{
|
||||
return new class extends AbstractExtension {
|
||||
return new class() extends AbstractExtension {
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -197,7 +197,7 @@ EOF
|
||||
$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()
|
||||
|
||||
@@ -452,12 +452,12 @@ class TemplateForTest extends Template
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class TypesTokenParserTest extends TestCase
|
||||
[
|
||||
'{% types {foo: "bar"} %}',
|
||||
[
|
||||
'foo' => ['type' => 'bar', 'optional' => false]
|
||||
'foo' => ['type' => 'bar', 'optional' => false],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -43,7 +43,7 @@ class TypesTokenParserTest extends TestCase
|
||||
[
|
||||
'{% types {foo: "bar",} %}',
|
||||
[
|
||||
'foo' => ['type' => 'bar', 'optional' => false]
|
||||
'foo' => ['type' => 'bar', 'optional' => false],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -51,7 +51,7 @@ class TypesTokenParserTest extends TestCase
|
||||
[
|
||||
'{% types {foo?: "bar"} %}',
|
||||
[
|
||||
'foo' => ['type' => 'bar', 'optional' => true]
|
||||
'foo' => ['type' => 'bar', 'optional' => true],
|
||||
],
|
||||
],
|
||||
|
||||
@@ -61,7 +61,7 @@ class TypesTokenParserTest extends TestCase
|
||||
[
|
||||
'foo' => ['type' => 'foo', 'optional' => false],
|
||||
'bar' => ['type' => 'foo', 'optional' => true],
|
||||
'baz' => ['type' => 'baz', 'optional' => false]
|
||||
'baz' => ['type' => 'baz', 'optional' => false],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user