Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Oct 8, 2023
1 parent 3ae6fb8 commit 8eefd74
Show file tree
Hide file tree
Showing 38 changed files with 102 additions and 142 deletions.
2 changes: 1 addition & 1 deletion extra/markdown-extra/MarkdownExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function twig_html_to_markdown(string $body, array $options = []): string
throw new \LogicException('You cannot use the "html_to_markdown" filter as league/html-to-markdown is not installed; try running "composer require league/html-to-markdown".');
}

$options = $options + [
$options += [
'hard_break' => true,
'strip_tags' => true,
'remove_nodes' => 'head style',
Expand Down
2 changes: 1 addition & 1 deletion extra/markdown-extra/Tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class FunctionalTest extends TestCase
*/
public function testMarkdown(string $template, string $expected): void
{
foreach ([LeagueMarkdown::class, ErusevMarkdown::class, /*MichelfMarkdown::class,*/ DefaultMarkdown::class] as $class) {
foreach ([LeagueMarkdown::class, ErusevMarkdown::class, /* MichelfMarkdown::class, */ DefaultMarkdown::class] as $class) {
$twig = new Environment(new ArrayLoader([
'index' => $template,
'html' => <<<EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function load(array $configs, ContainerBuilder $container)
if ($this->isConfigEnabled($container, $config[$extension])) {
$loader->load($extension.'.php');

if ('markdown' === $extension && \class_exists(CommonMarkConverter::class)) {
if ('markdown' === $extension && class_exists(CommonMarkConverter::class)) {
$loader->load('markdown_league.php');
}
}
Expand Down
2 changes: 1 addition & 1 deletion extra/twig-extra-bundle/Tests/Fixture/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use League\CommonMark\Extension\Strikethrough\StrikethroughExtension;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Twig\Extra\TwigExtraBundle\TwigExtraBundle;

class Kernel extends BaseKernel
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/FilesystemCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function write(string $key, string $content): void

if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
// Compile cached file into bytecode cache
if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) {
if (\function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) {
@opcache_invalidate($key, true);
} elseif (\function_exists('apc_compile_file')) {
apc_compile_file($key);
Expand Down
2 changes: 1 addition & 1 deletion src/ExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public function parseArguments($namedArguments = false, $definition = false, $al
$name = null;
if ($namedArguments && $token = $stream->nextIf(/* Token::OPERATOR_TYPE */ 8, '=')) {
if (!$value instanceof NameExpression) {
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
29 changes: 13 additions & 16 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ function twig_cycle($values, $position)
* @param \Traversable|array|int|float|string $values The values to pick a random item from
* @param int|null $max Maximum value used when $values is an int
*
* @throws RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is)
*
* @return mixed A random value from the given sequence
*
* @throws RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is)
*/
function twig_random(Environment $env, $values = null, $max = null)
{
Expand Down Expand Up @@ -530,7 +530,7 @@ function twig_date_converter(Environment $env, $date = null, $timezone = null)
function twig_replace_filter($str, $from)
{
if (!twig_test_iterable($from)) {
throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from)));
throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? $from::class : \gettype($from)));
}

return strtr($str ?? '', twig_to_array($from));
Expand Down Expand Up @@ -768,7 +768,7 @@ function twig_split_filter(Environment $env, $value, $delimiter, $limit = null)
{
$value = $value ?? '';

if (\strlen($delimiter) > 0) {
if ('' !== $delimiter) {
return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit);
}

Expand Down Expand Up @@ -1022,9 +1022,6 @@ function twig_compare($a, $b)
}

/**
* @param string $pattern
* @param string|null $subject
*
* @return int
*
* @throws RuntimeError When an invalid pattern is used
Expand Down Expand Up @@ -1123,7 +1120,7 @@ function twig_length_filter(Environment $env, $thing)
return 0;
}

if (is_scalar($thing)) {
if (\is_scalar($thing)) {
return mb_strlen($thing, $env->getCharset());
}

Expand Down Expand Up @@ -1386,10 +1383,10 @@ function twig_constant($constant, $object = null)
{
if (null !== $object) {
if ('class' === $constant) {
return \get_class($object);
return $object::class;
}

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

if (!\defined($constant)) {
Expand All @@ -1414,7 +1411,7 @@ function twig_constant_is_defined($constant, $object = null)
return true;
}

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

return \defined($constant);
Expand All @@ -1432,7 +1429,7 @@ function twig_constant_is_defined($constant, $object = null)
function twig_array_batch($items, $size, $fill = null, $preserveKeys = true)
{
if (!twig_test_iterable($items)) {
throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items)));
throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? $items::class : \gettype($items)));
}

$size = ceil($size);
Expand Down Expand Up @@ -1494,9 +1491,9 @@ function twig_get_attribute(Environment $env, Source $source, $object, $item, ar
}

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 (empty($object)) {
$message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem);
Expand Down Expand Up @@ -1560,7 +1557,7 @@ function twig_get_attribute(Environment $env, Source $source, $object, $item, ar

static $cache = [];

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

// object method
// precedence: getXxx() > isXxx() > hasXxx()
Expand Down Expand Up @@ -1676,7 +1673,7 @@ function twig_array_column($array, $name, $index = null): array
function twig_array_filter(Environment $env, $array, $arrow)
{
if (!twig_test_iterable($array)) {
throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array)));
throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? $array::class : \gettype($array)));
}

twig_check_arrow_in_sandbox($env, $arrow, 'filter', 'filter');
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/DebugExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public function getFunctions(): array
// dump is safe if var_dump is overridden by xdebug
$isDumpOutputHtmlSafe = \extension_loaded('xdebug')
// false means that it was not set (and the default is on) or it explicitly enabled
&& (false === ini_get('xdebug.overload_var_dump') || ini_get('xdebug.overload_var_dump'))
&& (false === \ini_get('xdebug.overload_var_dump') || \ini_get('xdebug.overload_var_dump'))
// false means that it was not set (and the default is on) or it explicitly enabled
// xdebug.overload_var_dump produces HTML only when html_errors is also enabled
&& (false === ini_get('html_errors') || ini_get('html_errors'))
&& (false === \ini_get('html_errors') || \ini_get('html_errors'))
|| 'cli' === \PHP_SAPI
;

Expand Down
6 changes: 3 additions & 3 deletions src/Extension/EscaperExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char
if (!\is_string($string)) {
if (\is_object($string) && method_exists($string, '__toString')) {
if ($autoescape) {
$c = \get_class($string);
$c = $string::class;
$ext = $env->getExtension(EscaperExtension::class);
if (!isset($ext->safeClasses[$c])) {
$ext->safeClasses[$c] = [];
Expand Down Expand Up @@ -341,7 +341,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char
* The following replaces characters undefined in HTML with the
* hex entity for the Unicode replacement character.
*/
if (($ord <= 0x1f && "\t" != $chr && "\n" != $chr && "\r" != $chr) || ($ord >= 0x7f && $ord <= 0x9f)) {
if (($ord <= 0x1F && "\t" != $chr && "\n" != $chr && "\r" != $chr) || ($ord >= 0x7F && $ord <= 0x9F)) {
return '&#xFFFD;';
}

Expand Down Expand Up @@ -388,7 +388,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char

default:
$escapers = $env->getExtension(EscaperExtension::class)->getEscapers();
if (array_key_exists($strategy, $escapers)) {
if (\array_key_exists($strategy, $escapers)) {
return $escapers[$strategy]($env, $string, $charset);
}

Expand Down
8 changes: 4 additions & 4 deletions src/ExtensionSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,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 @@ -330,7 +330,7 @@ public function getGlobals(): array

$extGlobals = $extension->getGlobals();
if (!\is_array($extGlobals)) {
throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', \get_class($extension)));
throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', $extension::class));
}

$globals = array_merge($globals, $extGlobals);
Expand Down Expand Up @@ -466,11 +466,11 @@ private function initExtension(ExtensionInterface $extension): void
// operators
if ($operators = $extension->getOperators()) {
if (!\is_array($operators)) {
throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array with operators, got "%s".', \get_class($extension), \is_object($operators) ? \get_class($operators) : \gettype($operators).(\is_resource($operators) ? '' : '#'.$operators)));
throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array with operators, got "%s".', $extension::class, \is_object($operators) ? $operators::class : \gettype($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)));
}

$this->unaryOperators = array_merge($this->unaryOperators, $operators[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private function lexString(): void
$this->pushToken(/* Token::INTERPOLATION_START_TYPE */ 10);
$this->moveCursor($match[0]);
$this->pushState(self::STATE_INTERPOLATION);
} elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && \strlen($match[0]) > 0) {
} elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && '' !== $match[0]) {
$this->pushToken(/* Token::STRING_TYPE */ 7, stripcslashes($match[0]));
$this->moveCursor($match[0]);
} elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Loader/ChainLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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 @@ -110,7 +110,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 @@ -41,9 +41,6 @@ public function count()
return mb_strlen($this->content, $this->charset);
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/CallExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private function reflectCallable($callable)

if ($object = $r->getClosureThis()) {
$callable = [$object, $r->name];
$callableName = (\function_exists('get_debug_type') ? get_debug_type($object) : \get_class($object)).'::'.$r->name;
$callableName = (\function_exists('get_debug_type') ? get_debug_type($object) : $object::class).'::'.$r->name;
} elseif (\PHP_VERSION_ID >= 80111 && $class = $r->getClosureCalledClass()) {
$callableName = $class->name.'::'.$r->name;
} elseif (\PHP_VERSION_ID < 80111 && $class = $r->getClosureScopeClass()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ 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;
Expand Down
2 changes: 1 addition & 1 deletion src/NodeVisitor/EscaperNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private function escapePrintNode(PrintNode $node, Environment $env, string $type
return $node;
}

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

return new $class($this->getEscaperFilter($type, $expression), $node->getTemplateLine());
}
Expand Down
8 changes: 4 additions & 4 deletions src/NodeVisitor/MacroAutoImportNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public function leaveNode(Node $node, Environment $env): Node
}
} elseif ($this->inAModule) {
if (
$node instanceof GetAttrExpression &&
$node->getNode('node') instanceof NameExpression &&
'_self' === $node->getNode('node')->getAttribute('name') &&
$node->getNode('attribute') instanceof ConstantExpression
$node instanceof GetAttrExpression
&& $node->getNode('node') instanceof NameExpression
&& '_self' === $node->getNode('node')->getAttribute('name')
&& $node->getNode('attribute') instanceof ConstantExpression
) {
$this->hasMacroCalls = true;

Expand Down
16 changes: 8 additions & 8 deletions src/NodeVisitor/OptimizerNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ private function optimizePrintNode(Node $node, Environment $env): Node

$exprNode = $node->getNode('expr');
if (
$exprNode instanceof BlockReferenceExpression ||
$exprNode instanceof ParentExpression
$exprNode instanceof BlockReferenceExpression
|| $exprNode instanceof ParentExpression
) {
$exprNode->setAttribute('output', true);

Expand Down Expand Up @@ -166,7 +166,7 @@ private function enterOptimizeFor(Node $node, Environment $env): void
&& 'include' === $node->getAttribute('name')
&& (!$node->getNode('arguments')->hasNode('with_context')
|| false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value')
)
)
) {
$this->addLoopToAll();
}
Expand All @@ -175,12 +175,12 @@ private function enterOptimizeFor(Node $node, Environment $env): void
elseif ($node instanceof GetAttrExpression
&& (!$node->getNode('attribute') instanceof ConstantExpression
|| 'parent' === $node->getNode('attribute')->getAttribute('value')
)
)
&& (true === $this->loops[0]->getAttribute('with_loop')
|| ($node->getNode('node') instanceof NameExpression
&& 'loop' === $node->getNode('node')->getAttribute('name')
)
)
|| ($node->getNode('node') instanceof NameExpression
&& 'loop' === $node->getNode('node')->getAttribute('name')
)
)
) {
$this->addLoopToAll();
}
Expand Down
5 changes: 2 additions & 3 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@ private function filterBodyNodes(Node $node, bool $nested = false): ?Node
// check that the body does not contain non-empty output nodes
if (
($node instanceof TextNode && !ctype_space($node->getAttribute('data')))
||
(!$node instanceof TextNode && !$node instanceof BlockReferenceNode && $node instanceof NodeOutputInterface)
|| (!$node instanceof TextNode && !$node instanceof BlockReferenceNode && $node instanceof NodeOutputInterface)
) {
if (false !== strpos((string) $node, \chr(0xEF).\chr(0xBB).\chr(0xBF))) {
$t = substr($node->getAttribute('data'), 3);
Expand Down Expand Up @@ -336,7 +335,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
$nested = $nested || Node::class !== \get_class($node);
$nested = $nested || Node::class !== $node::class;
foreach ($node as $k => $n) {
if (null !== $n && null === $this->filterBodyNodes($n, $nested)) {
$node->removeNode($k);
Expand Down
Loading

0 comments on commit 8eefd74

Please sign in to comment.