Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Nov 30, 2024
1 parent cf105b5 commit 82cde4e
Show file tree
Hide file tree
Showing 20 changed files with 22 additions and 29 deletions.
6 changes: 3 additions & 3 deletions extra/html-extra/HtmlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ public static function htmlClasses(...$args): string
}

/**
* @param string|list<string|null> $base
* @param string|list<string|null> $base
* @param array<string, array<string, string|array<string>> $variants
* @param array<array<string, string|array<string>>> $compoundVariants
* @param array<string, string> $defaultVariant
* @param array<array<string, string|array<string>>> $compoundVariants
* @param array<string, string> $defaultVariant
*
* @internal
*/
Expand Down
2 changes: 1 addition & 1 deletion extra/twig-extra-bundle/phpunit-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use Symfony\Component\ErrorHandler\ErrorHandler;

require __DIR__ . '/vendor/autoload.php';
require __DIR__.'/vendor/autoload.php';

// see https://github.com/symfony/symfony/issues/53812#issuecomment-1962740145
set_exception_handler([new ErrorHandler(), 'handleException']);
6 changes: 2 additions & 4 deletions src/ExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\GetAttrExpression;
use Twig\Node\Expression\MacroReferenceExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Ternary\ConditionalTernary;
use Twig\Node\Expression\TestExpression;
use Twig\Node\Expression\Unary\AbstractUnary;
Expand Down Expand Up @@ -782,7 +781,7 @@ public function parseOnlyArguments()
$name = null;
if (($token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) || ($token = $stream->nextIf(Token::PUNCTUATION_TYPE, ':'))) {
if (!$value instanceof ContextVariable) {
throw new SyntaxError(\sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext());
throw new SyntaxError(\sprintf('A parameter name must be a string, "%s" given.', $value::class), $token->getLine(), $stream->getSourceContext());
}
$name = $value->getAttribute('name');
$value = $this->parseExpression();
Expand Down Expand Up @@ -830,8 +829,7 @@ private function parseSubscriptExpressionDot(Node $node): AbstractExpression

if (
$node instanceof ContextVariable
&&
(
&& (
null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))
|| '_self' === $node->getAttribute('name') && $attribute instanceof ConstantExpression
)
Expand Down
3 changes: 1 addition & 2 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,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)) {
throw new RuntimeError('The "cycle" function expects a countable sequence as first argument.');
}

Expand Down Expand Up @@ -504,7 +504,6 @@ public function modifyDate($date, $modifier): \DateTimeImmutable
* Returns a formatted string.
*
* @param string|null $format
* @param ...$values
*
* @internal
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ private function stripcslashes(string $str, string $quoteType): string

if (isset(self::SPECIAL_CHARS[$nextChar])) {
$result .= self::SPECIAL_CHARS[$nextChar];
} elseif ($nextChar === '\\' || $nextChar === $quoteType) {
} elseif ('\\' === $nextChar || $nextChar === $quoteType) {
$result .= $nextChar;
} elseif ('#' === $nextChar && $i + 1 < $length && '{' === $str[$i + 1]) {
$result .= '#{';
Expand Down
1 change: 0 additions & 1 deletion src/Node/Expression/CallExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Twig\Compiler;
use Twig\Extension\ExtensionInterface;
use Twig\TwigCallableInterface;
use Twig\Util\CallableArgumentsExtractor;
use Twig\Util\ReflectionCallable;

Expand Down
1 change: 0 additions & 1 deletion src/Node/Expression/Variable/AssignContextVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Twig\Compiler;
use Twig\Error\SyntaxError;
use Twig\Node\Expression\Variable\ContextVariable;

final class AssignContextVariable extends ContextVariable
{
Expand Down
6 changes: 3 additions & 3 deletions src/Node/Expression/Variable/LocalVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Twig\Node\Expression\Variable;

use Twig\Error\SyntaxError;
use Twig\Compiler;
use Twig\Error\SyntaxError;
use Twig\Node\Expression\AbstractExpression;

final class LocalVariable extends AbstractExpression
Expand All @@ -26,9 +26,9 @@ public function __construct(string|int|null $name, int $lineno)
throw new SyntaxError(\sprintf('You cannot assign a value to "%s".', $name), $lineno);
}

if (null !== $name && (is_int($name) || ctype_digit($name))) {
if (null !== $name && (\is_int($name) || ctype_digit($name))) {
$name = (int) $name;
} elseif (in_array($name, self::RESERVED_NAMES)) {
} elseif (\in_array($name, self::RESERVED_NAMES)) {
$name = "\u{035C}".$name;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Node/Expression/Variable/TemplateVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function __construct(string|int|null $name, int $lineno)
throw new SyntaxError(\sprintf('You cannot assign a value to "%s".', $name), $lineno);
}

if (null !== $name && (is_int($name) || ctype_digit($name))) {
if (null !== $name && (\is_int($name) || ctype_digit($name))) {
$name = (int) $name;
} elseif (in_array($name, self::RESERVED_NAMES)) {
} elseif (\in_array($name, self::RESERVED_NAMES)) {
$name = "\u{035C}".$name;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Node/ForNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function compile(Compiler $compiler): void
}

$compiler
->write("foreach (\$iterator as ")
->write('foreach ($iterator as ')
->subcompile($this->getNode('key_target'))
->raw(' => ')
->subcompile($this->getNode('value_target'))
Expand Down
1 change: 0 additions & 1 deletion src/Node/MacroNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Twig\Compiler;
use Twig\Error\SyntaxError;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\Variable\LocalVariable;

/**
* Represents a macro node.
Expand Down
2 changes: 1 addition & 1 deletion src/Node/SetNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(bool $capture, Node $names, Node $values, int $linen
$safe = false;
if ($capture) {
$safe = true;
if ($values instanceof Nodes && !count($values)) {
if ($values instanceof Nodes && !\count($values)) {
$values = new ConstantExpression('', $values->getTemplateLine());
$capture = false;
} elseif ($values instanceof TextNode) {
Expand Down
2 changes: 1 addition & 1 deletion src/NodeVisitor/OptimizerNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class OptimizerNodeVisitor implements NodeVisitorInterface
public function __construct(
private int $optimizers = -1,
) {
if ($optimizers > (self::OPTIMIZE_FOR)) {
if ($optimizers > self::OPTIMIZE_FOR) {
throw new \InvalidArgumentException(\sprintf('Optimizer mode "%s" is not valid.', $optimizers));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/NodeVisitor/SandboxNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\Expression\GetAttrExpression;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\Expression\Unary\SpreadUnary;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\ModuleNode;
use Twig\Node\Node;
use Twig\Node\Nodes;
Expand Down
2 changes: 0 additions & 2 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
use Twig\Node\BlockReferenceNode;
use Twig\Node\BodyNode;
use Twig\Node\EmptyNode;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\Variable\AssignTemplateVariable;
use Twig\Node\Expression\Variable\TemplateVariable;
use Twig\Node\MacroNode;
use Twig\Node\ModuleNode;
use Twig\Node\Node;
Expand Down
1 change: 1 addition & 0 deletions src/Runtime/LoopIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*
* @template TKey
* @template TValue
*
* @implements \Iterator<TKey, TValue>
*/
final class LoopIterator implements \Iterator
Expand Down
1 change: 1 addition & 0 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ protected function loadTemplate(string|TemplateWrapper|array $template, $templat

/**
* @internal
*
* @return $this
*/
public function unwrap(): self
Expand Down
4 changes: 2 additions & 2 deletions tests/DeprecatedCallableInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testTriggerDeprecation($expected, DeprecatedCallableInfo $info)
if (\E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
}

return false;
});

Expand Down Expand Up @@ -62,7 +62,7 @@ public function testTriggerDeprecationWithoutFileOrLine()
if (\E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
}

return false;
});

Expand Down
1 change: 0 additions & 1 deletion tests/Extension/SandboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Twig\Environment;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Extension\SandboxExtension;
use Twig\Extension\StringLoaderExtension;
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 @@ -114,7 +114,7 @@ public static function provideTests(): iterable

// from extension
$node = self::createFilter($environment, $string, 'foo');
$tests[] = [$node, \sprintf('$this->extensions[\'%s\']->foo("abc")', get_class(self::createExtension())), $environment];
$tests[] = [$node, \sprintf('$this->extensions[\'%s\']->foo("abc")', \get_class(self::createExtension())), $environment];

$node = self::createFilter($environment, $string, 'foobar');
$tests[] = [$node, '$this->env->getFilter(\'foobar\')->getCallable()("abc")', $environment];
Expand Down

0 comments on commit 82cde4e

Please sign in to comment.