Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Sep 6, 2024
1 parent b1cdda2 commit 2ae0c0d
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/ExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');

Expand Down
6 changes: 3 additions & 3 deletions src/Node/ImportNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down
6 changes: 3 additions & 3 deletions src/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public function render(array $context): string
}

/**
* @return iterable<null|scalar|\Stringable>
* @return iterable<scalar|\Stringable|null>
*/
public function yield(array $context, array $blocks = []): iterable
{
Expand Down Expand Up @@ -412,7 +412,7 @@ public function yield(array $context, array $blocks = []): iterable
}

/**
* @return iterable<null|scalar|\Stringable>
* @return iterable<scalar|\Stringable|null>
*/
public function yieldBlock($name, array $context, array $blocks = [], $useBlocks = true, ?self $templateContext = null): iterable
{
Expand Down Expand Up @@ -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<null|scalar|\Stringable>
* @return iterable<scalar|\Stringable|null>
*/
public function yieldParentBlock($name, array $context, array $blocks = []): iterable
{
Expand All @@ -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<null|scalar|\Stringable>
* @return iterable<scalar|\Stringable|null>
*/
abstract protected function doDisplay(array $context, array $blocks = []): iterable;
}
2 changes: 1 addition & 1 deletion src/Test/NodeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/TokenParser/TypesTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/Extension/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -53,7 +53,8 @@ public static function provideCycleInvalidCases()
{
return [
'empty' => [[]],
'non-countable' => [new class extends \ArrayObject{}],
'non-countable' => [new class() extends \ArrayObject {
}],
];
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Extension/SandboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
}
Expand All @@ -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 %}'];
Expand All @@ -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 %}'];
}

Expand All @@ -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([]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Node/Expression/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
2 changes: 1 addition & 1 deletion tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
8 changes: 4 additions & 4 deletions tests/TokenParser/TypesTokenParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ public static function getMappingTests(): array
[
'{% types {foo: "bar"} %}',
[
'foo' => ['type' => 'bar', 'optional' => false]
'foo' => ['type' => 'bar', 'optional' => false],
],
],

// trailing comma
[
'{% types {foo: "bar",} %}',
[
'foo' => ['type' => 'bar', 'optional' => false]
'foo' => ['type' => 'bar', 'optional' => false],
],
],

// optional name
[
'{% types {foo?: "bar"} %}',
[
'foo' => ['type' => 'bar', 'optional' => true]
'foo' => ['type' => 'bar', 'optional' => true],
],
],

Expand All @@ -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],
],
],
];
Expand Down

0 comments on commit 2ae0c0d

Please sign in to comment.