Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Feb 14, 2025
1 parent 640b382 commit 151aa4e
Show file tree
Hide file tree
Showing 32 changed files with 44 additions and 71 deletions.
2 changes: 1 addition & 1 deletion extra/html-extra/HtmlExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function dataUri(string $data, ?string $mime = null, array $parameters =
$repr .= ';'.$key.'='.rawurlencode($value);
}

if (0 === strpos($mime, 'text/')) {
if (str_starts_with($mime, 'text/')) {
$repr .= ','.rawurlencode($data);
} else {
$repr .= ';base64,'.base64_encode($data);
Expand Down
4 changes: 2 additions & 2 deletions extra/twig-extra-bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ private function addCommonMarkConfiguration(ArrayNodeDefinition $rootNode): void
->end()
->enumNode('html_input')
->info('How to handle HTML input.')
->values(['strip','allow','escape'])
->values(['strip', 'allow', 'escape'])
->end()
->booleanNode('allow_unsafe_links')
->info('Remove risky link and image URLs by setting this to false.')
->defaultTrue()
->end()
->integerNode('max_nesting_level')
->info('The maximum nesting level for blocks.')
->defaultValue(PHP_INT_MAX)
->defaultValue(\PHP_INT_MAX)
->end()
->arrayNode('slug_normalizer')
->info('Array of options for configuring how URL-safe slugs are created.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public function testDefaultConfiguration()
]));
$container->registerExtension(new TwigExtraExtension());
$container->loadFromExtension('twig_extra', [
'commonmark' => [
'commonmark' => [
'extra_key' => true,
'renderer' => [
'block_separator' => "\n",
'inner_separator' => "\n",
'soft_break' => "\n",
'soft_break' => "\n",
],
'commonmark' => [
'enable_em' => true,
Expand All @@ -43,7 +43,7 @@ public function testDefaultConfiguration()
],
'html_input' => 'escape',
'allow_unsafe_links' => false,
'max_nesting_level' => PHP_INT_MAX,
'max_nesting_level' => \PHP_INT_MAX,
'slug_normalizer' => [
'max_length' => 255,
],
Expand Down
4 changes: 2 additions & 2 deletions src/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function compile(Node $node, int $indentation = 0)
$node->compile($this);

if ($this->didUseEcho) {
trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[\Twig\Attribute\YieldReady].', $this->didUseEcho, \get_class($node));
trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[\Twig\Attribute\YieldReady].', $this->didUseEcho, $node::class);
}

return $this;
Expand All @@ -99,7 +99,7 @@ public function subcompile(Node $node, bool $raw = true)
$node->compile($this);

if ($this->didUseEcho) {
trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[\Twig\Attribute\YieldReady].', $this->didUseEcho, \get_class($node));
trigger_deprecation('twig/twig', '3.9', 'Using "%s" is deprecated, use "yield" instead in "%s", then flag the class with #[\Twig\Attribute\YieldReady].', $this->didUseEcho, $node::class);
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/ExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function parseArguments()
$name = null;
if ($namedArguments && (($token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) || (!$definition && $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');

Expand Down
1 change: 0 additions & 1 deletion src/ExpressionParser/Prefix/LiteralExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\Binary\ConcatBinary;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\Unary\SpreadUnary;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Parser;
use Twig\Token;
Expand Down
17 changes: 5 additions & 12 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ public function modifyDate($date, $modifier)
* Returns a formatted string.
*
* @param string|null $format
* @param ...$values
*
* @internal
*/
Expand Down Expand Up @@ -1001,8 +1000,6 @@ public static function reverse(string $charset, $item, $preserveKeys = false)
*
* @param array|\Traversable|string|null $item
*
* @return mixed
*
* @internal
*/
public static function shuffle(string $charset, $item)
Expand Down Expand Up @@ -1437,8 +1434,6 @@ public static function testEmpty($value): bool
* {# ... #}
* {% endif %}
*
* @param mixed $value
*
* @internal
*/
public static function testSequence($value): bool
Expand All @@ -1462,8 +1457,6 @@ public static function testSequence($value): bool
* {# ... #}
* {% endif %}
*
* @param mixed $value
*
* @internal
*/
public static function testMapping($value): bool
Expand Down Expand Up @@ -1613,10 +1606,10 @@ public static function constant($constant, $object = null, bool $checkDefined =
{
if (null !== $object) {
if ('class' === $constant) {
return $checkDefined ? true : \get_class($object);
return $checkDefined ? true : $object::class;
}

$constant = \get_class($object).'::'.$constant;
$constant = $object::class.'::'.$constant;
}

if (!\defined($constant)) {
Expand Down Expand Up @@ -1720,9 +1713,9 @@ public static function getAttribute(Environment $env, Source $source, $object, $
}

if ($object instanceof \ArrayAccess) {
$message = \sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($object));
$message = \sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, $object::class);
} elseif (\is_object($object)) {
$message = \sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, \get_class($object));
$message = \sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, $object::class);
} elseif (\is_array($object)) {
if (!$object) {
$message = \sprintf('Key "%s" does not exist as the sequence/mapping is empty.', $arrayItem);
Expand Down Expand Up @@ -1818,7 +1811,7 @@ public static function getAttribute(Environment $env, Source $source, $object, $

static $cache = [];

$class = \get_class($object);
$class = $object::class;

// object method
// precedence: getXxx() > isXxx() > hasXxx()
Expand Down
4 changes: 0 additions & 4 deletions src/Extension/SandboxExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ public function checkPropertyAllowed($obj, $property, int $lineno = -1, ?Source
}

/**
* @param mixed $obj
*
* @return mixed
*
* @throws SecurityNotAllowedMethodError
*/
public function ensureToStringAllowed($obj, int $lineno = -1, ?Source $source = null)
Expand Down
6 changes: 3 additions & 3 deletions src/ExtensionSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function getLastModified(): int

public function addExtension(ExtensionInterface $extension): void
{
$class = \get_class($extension);
$class = $extension::class;

if ($this->initialized) {
throw new \LogicException(\sprintf('Unable to register extension "%s" as extensions have already been initialized.', $class));
Expand Down Expand Up @@ -484,11 +484,11 @@ private function initExtension(ExtensionInterface $extension): void

$operators = $extension->getOperators();
if (!\is_array($operators)) {
throw new \InvalidArgumentException(\sprintf('"%s::getOperators()" must return an array with operators, got "%s".', \get_class($extension), get_debug_type($operators).(\is_resource($operators) ? '' : '#'.$operators)));
throw new \InvalidArgumentException(\sprintf('"%s::getOperators()" must return an array with operators, got "%s".', $extension::class, get_debug_type($operators).(\is_resource($operators) ? '' : '#'.$operators)));
}

if (2 !== \count($operators)) {
throw new \InvalidArgumentException(\sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', \get_class($extension), \count($operators)));
throw new \InvalidArgumentException(\sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', $extension::class, \count($operators)));
}

$expressionParsers = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Loader/ChainLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function getCacheKey(string $name): string
try {
return $loader->getCacheKey($name);
} catch (LoaderError $e) {
$exceptions[] = \get_class($loader).': '.$e->getMessage();
$exceptions[] = $loader::class.': '.$e->getMessage();
}
}

Expand All @@ -123,7 +123,7 @@ public function isFresh(string $name, int $time): bool
try {
return $loader->isFresh($name, $time);
} catch (LoaderError $e) {
$exceptions[] = \get_class($loader).': '.$e->getMessage();
$exceptions[] = $loader::class.': '.$e->getMessage();
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/Markup.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public function count()
return mb_strlen($this->content, $this->charset);
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Node/Expression/Binary/AbstractBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ abstract class AbstractBinary extends AbstractExpression implements BinaryInterf
public function __construct(Node $left, Node $right, int $lineno)
{
if (!$left instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($left));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $left::class);
}
if (!$right instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($right));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $right::class);
}

parent::__construct(['left' => $left, 'right' => $right], [], $lineno);
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/BlockReferenceExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BlockReferenceExpression extends AbstractExpression
public function __construct(Node $name, ?Node $template, int $lineno)
{
if (!$name instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($name));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $name::class);
}

$nodes = ['name' => $name];
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Filter/DefaultFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DefaultFilter extends FilterExpression
public function __construct(Node $node, TwigFilter|ConstantExpression $filter, Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}

if ($filter instanceof TwigFilter) {
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Filter/RawFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RawFilter extends FilterExpression
public function __construct(Node $node, TwigFilter|ConstantExpression|null $filter = null, ?Node $arguments = null, int $lineno = 0)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}

parent::__construct($node, $filter ?: new TwigFilter('raw', null, ['is_safe' => ['all']]), $arguments ?: new EmptyNode(), $lineno ?: $node->getTemplateLine());
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/FilterExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class FilterExpression extends CallExpression
public function __construct(Node $node, TwigFilter|ConstantExpression $filter, Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}

if ($filter instanceof TwigFilter) {
Expand Down
4 changes: 2 additions & 2 deletions src/Node/Expression/NullCoalesceExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public function __construct(Node $left, Node $right, int $lineno)
trigger_deprecation('twig/twig', '3.17', \sprintf('"%s" is deprecated; use "%s" instead.', __CLASS__, NullCoalesceBinary::class));

if (!$left instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($left));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $left::class);
}
if (!$right instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($right));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $right::class);
}

$test = new DefinedTest(clone $left, new TwigTest('defined'), new EmptyNode(), $left->getTemplateLine());
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Test/DefinedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DefinedTest extends TestExpression
public function __construct(Node $node, TwigTest|string $name, ?Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}

if ($node instanceof ContextVariable) {
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/TestExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TestExpression extends CallExpression
public function __construct(Node $node, string|TwigTest $test, ?Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}

$nodes = ['node' => $node];
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Unary/AbstractUnary.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class AbstractUnary extends AbstractExpression implements UnaryInterfac
public function __construct(Node $node, int $lineno)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance argument to "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance argument to "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, $node::class);
}

parent::__construct(['node' => $node], ['with_parentheses' => false], $lineno);
Expand Down
3 changes: 0 additions & 3 deletions src/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ public function hasAttribute(string $name): bool
return \array_key_exists($name, $this->attributes);
}

/**
* @return mixed
*/
public function getAttribute(string $name)
{
if (!\array_key_exists($name, $this->attributes)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Node/SetNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(bool $capture, Node $names, Node $values, int $linen
if ($capture) {
$safe = true;
// Node::class === get_class($values) should be removed in Twig 4.0
if (($values instanceof Nodes || Node::class === \get_class($values)) && !\count($values)) {
if (($values instanceof Nodes || Node::class === $values::class) && !\count($values)) {
$values = new ConstantExpression('', $values->getTemplateLine());
$capture = false;
} elseif ($values instanceof TextNode) {
Expand Down
2 changes: 1 addition & 1 deletion src/NodeVisitor/YieldNotReadyNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(

public function enterNode(Node $node, Environment $env): Node
{
$class = \get_class($node);
$class = $node::class;

if ($node instanceof AbstractExpression || isset($this->yieldReadyNodes[$class])) {
return $node;
Expand Down
2 changes: 1 addition & 1 deletion src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ private function filterBodyNodes(Node $node, bool $nested = false): ?Node
// here, $nested means "being at the root level of a child template"
// we need to discard the wrapping "Node" for the "body" node
// Node::class !== \get_class($node) should be removed in Twig 4.0
$nested = $nested || (Node::class !== \get_class($node) && !$node instanceof Nodes);
$nested = $nested || (Node::class !== $node::class && !$node instanceof Nodes);
foreach ($node as $k => $n) {
if (null !== $n && null === $this->filterBodyNodes($n, $nested)) {
$node->removeNode($k);
Expand Down
2 changes: 1 addition & 1 deletion src/Runtime/EscaperRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function escape($string, string $strategy = 'html', ?string $charset = nu
if (!\is_string($string)) {
if ($string instanceof \Stringable) {
if ($autoescape) {
$c = \get_class($string);
$c = $string::class;
if (!isset($this->safeClasses[$c])) {
$this->safeClasses[$c] = [];
foreach (class_parents($string) + class_implements($string) as $class) {
Expand Down
Loading

0 comments on commit 151aa4e

Please sign in to comment.