Skip to content

Commit

Permalink
minor #3882 Fix CS (fabpot)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

Fix CS

Commits
-------

5193653 Fix CS
  • Loading branch information
fabpot committed Oct 8, 2023
2 parents 3ae6fb8 + 5193653 commit 2d37866
Show file tree
Hide file tree
Showing 29 changed files with 72 additions and 112 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
11 changes: 4 additions & 7 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 @@ -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
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
4 changes: 2 additions & 2 deletions src/Extension/EscaperExtension.php
Original file line number Diff line number Diff line change
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
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
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
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
3 changes: 1 addition & 2 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
3 changes: 2 additions & 1 deletion src/Test/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function testIntegration($file, $message, $condition, $templates, $except

/**
* @dataProvider getLegacyTests
*
* @group legacy
*/
public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '')
Expand Down Expand Up @@ -257,7 +258,7 @@ protected static function parseTemplates($test)
$templates = [];
preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, \PREG_SET_ORDER);
foreach ($matches as $match) {
$templates[($match[1] ?: 'index.twig')] = $match[2];
$templates[$match[1] ?: 'index.twig'] = $match[2];
}

return $templates;
Expand Down
6 changes: 3 additions & 3 deletions src/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function test($type, $values = null): bool
}

return ($this->type === $type) && (
null === $values ||
(\is_array($values) && \in_array($this->value, $values)) ||
$this->value == $values
null === $values
|| (\is_array($values) && \in_array($this->value, $values))
|| $this->value == $values
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/TokenParser/FromTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function parse(Token $token): Node
$stream->expect(/* Token::NAME_TYPE */ 5, 'import');

$targets = [];
do {
while (true) {
$name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue();

$alias = $name;
Expand All @@ -45,7 +45,7 @@ public function parse(Token $token): Node
if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) {
break;
}
} while (true);
}

$stream->expect(/* Token::BLOCK_END_TYPE */ 3);

Expand Down
4 changes: 2 additions & 2 deletions src/TokenParser/UseTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function parse(Token $token): Node

$targets = [];
if ($stream->nextIf('with')) {
do {
while (true) {
$name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue();

$alias = $name;
Expand All @@ -56,7 +56,7 @@ public function parse(Token $token): Node
if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) {
break;
}
} while (true);
}
}

$stream->expect(/* Token::BLOCK_END_TYPE */ 3);
Expand Down
6 changes: 0 additions & 6 deletions src/Util/TemplateDirIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@
*/
class TemplateDirIterator extends \IteratorIterator
{
/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function current()
{
return file_get_contents(parent::current());
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function key()
{
Expand Down
6 changes: 0 additions & 6 deletions tests/Extension/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,6 @@ public function rewind(): void
$this->position = 0;
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function current()
{
Expand All @@ -393,9 +390,6 @@ public function current()
throw new \LogicException('Code should only use the keys, not the values provided by iterator.');
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function key()
{
Expand Down
24 changes: 12 additions & 12 deletions tests/Extension/EscaperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ public function testJavascriptEscapingConvertsSpecialCharsWithInternalEncoding()
try {
mb_internal_encoding('ISO-8859-1');
foreach ($this->jsSpecialChars as $key => $value) {
$this->assertEquals($value, twig_escape_filter($twig, $key, 'js'), 'Failed to escape: ' . $key);
$this->assertEquals($value, twig_escape_filter($twig, $key, 'js'), 'Failed to escape: '.$key);
}
} finally {
if ($previousInternalEncoding !== false) {
if (false !== $previousInternalEncoding) {
mb_internal_encoding($previousInternalEncoding);
}
}
Expand Down Expand Up @@ -249,7 +249,7 @@ public function testUrlEscapingConvertsSpecialChars()
public function testUnicodeCodepointConversionToUtf8()
{
$expected = '';
$codepoints = [0x20, 0x7e, 0x799];
$codepoints = [0x20, 0x7E, 0x799];
$result = '';
foreach ($codepoints as $value) {
$result .= $this->codepointToUtf8($value);
Expand All @@ -270,19 +270,19 @@ protected function codepointToUtf8($codepoint)
return \chr($codepoint);
}
if ($codepoint < 0x800) {
return \chr($codepoint >> 6 & 0x3f | 0xc0)
.\chr($codepoint & 0x3f | 0x80);
return \chr($codepoint >> 6 & 0x3F | 0xC0)
.\chr($codepoint & 0x3F | 0x80);
}
if ($codepoint < 0x10000) {
return \chr($codepoint >> 12 & 0x0f | 0xe0)
.\chr($codepoint >> 6 & 0x3f | 0x80)
.\chr($codepoint & 0x3f | 0x80);
return \chr($codepoint >> 12 & 0x0F | 0xE0)
.\chr($codepoint >> 6 & 0x3F | 0x80)
.\chr($codepoint & 0x3F | 0x80);
}
if ($codepoint < 0x110000) {
return \chr($codepoint >> 18 & 0x07 | 0xf0)
.\chr($codepoint >> 12 & 0x3f | 0x80)
.\chr($codepoint >> 6 & 0x3f | 0x80)
.\chr($codepoint & 0x3f | 0x80);
return \chr($codepoint >> 18 & 0x07 | 0xF0)
.\chr($codepoint >> 12 & 0x3F | 0x80)
.\chr($codepoint >> 6 & 0x3F | 0x80)
.\chr($codepoint & 0x3F | 0x80);
}
throw new \Exception('Codepoint requested outside of Unicode range.');
}
Expand Down
12 changes: 0 additions & 12 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,12 @@ public function rewind(): void
$this->position = 0;
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->array[$this->position];
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function key()
{
Expand Down Expand Up @@ -371,9 +365,6 @@ class SimpleIteratorForTesting implements \Iterator
private $data = [1, 2, 3, 4, 5, 6, 7];
private $key = 0;

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function current()
{
Expand All @@ -385,9 +376,6 @@ public function next(): void
++$this->key;
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function key()
{
Expand Down
Loading

0 comments on commit 2d37866

Please sign in to comment.