diff --git a/src/ExpressionParser.php b/src/ExpressionParser.php index 243c7f672..5da4db51b 100644 --- a/src/ExpressionParser.php +++ b/src/ExpressionParser.php @@ -255,7 +255,9 @@ class ExpressionParser $this->parser->getStream()->next(); $node = new NameExpression($token->getValue(), $token->getLine()); break; - } elseif (isset($this->unaryOperators[$token->getValue()])) { + } + + if (isset($this->unaryOperators[$token->getValue()])) { $class = $this->unaryOperators[$token->getValue()]['class']; if (!\in_array($class, [NegUnary::class, PosUnary::class])) { throw new SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index 7e9fd7659..5ad41c247 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -649,7 +649,7 @@ function twig_slice(Environment $env, $item, $start, $length = null, $preserveKe $item = (string) $item; - return (string) mb_substr($item, $start, $length, $env->getCharset()); + return mb_substr($item, $start, $length, $env->getCharset()); } /** @@ -802,8 +802,8 @@ function twig_get_array_keys_filter($array) $array = $array->getIterator(); } + $keys = []; if ($array instanceof \Iterator) { - $keys = []; $array->rewind(); while ($array->valid()) { $keys[] = $array->key(); @@ -813,7 +813,6 @@ function twig_get_array_keys_filter($array) return $keys; } - $keys = []; foreach ($array as $key => $item) { $keys[] = $key; } diff --git a/src/Loader/ArrayLoader.php b/src/Loader/ArrayLoader.php index a6164bb1a..5d726c35a 100644 --- a/src/Loader/ArrayLoader.php +++ b/src/Loader/ArrayLoader.php @@ -45,7 +45,6 @@ final class ArrayLoader implements LoaderInterface public function getSourceContext(string $name): Source { - $name = (string) $name; if (!isset($this->templates[$name])) { throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); } diff --git a/src/Loader/FilesystemLoader.php b/src/Loader/FilesystemLoader.php index 0db9e937c..a15033168 100644 --- a/src/Loader/FilesystemLoader.php +++ b/src/Loader/FilesystemLoader.php @@ -51,7 +51,7 @@ class FilesystemLoader implements LoaderInterface */ public function getPaths(string $namespace = self::MAIN_NAMESPACE): array { - return isset($this->paths[$namespace]) ? $this->paths[$namespace] : []; + return $this->paths[$namespace] ?? []; } /** diff --git a/src/Node/IncludeNode.php b/src/Node/IncludeNode.php index d01f1fca3..d540d6b23 100644 --- a/src/Node/IncludeNode.php +++ b/src/Node/IncludeNode.php @@ -29,7 +29,7 @@ class IncludeNode extends Node implements NodeOutputInterface $nodes['variables'] = $variables; } - parent::__construct($nodes, ['only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing], $lineno, $tag); + parent::__construct($nodes, ['only' => $only, 'ignore_missing' => $ignoreMissing], $lineno, $tag); } public function compile(Compiler $compiler): void diff --git a/src/NodeVisitor/EscaperNodeVisitor.php b/src/NodeVisitor/EscaperNodeVisitor.php index fafceb4db..fe56ea307 100644 --- a/src/NodeVisitor/EscaperNodeVisitor.php +++ b/src/NodeVisitor/EscaperNodeVisitor.php @@ -196,7 +196,7 @@ final class EscaperNodeVisitor implements NodeVisitorInterface { $line = $node->getTemplateLine(); $name = new ConstantExpression('escape', $line); - $args = new Node([new ConstantExpression((string) $type, $line), new ConstantExpression(null, $line), new ConstantExpression(true, $line)]); + $args = new Node([new ConstantExpression($type, $line), new ConstantExpression(null, $line), new ConstantExpression(true, $line)]); return new FilterExpression($node, $name, $args, $line); } diff --git a/src/Parser.php b/src/Parser.php index b8aac05f2..6103695e0 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -193,7 +193,7 @@ class Parser public function peekBlockStack() { - return isset($this->blockStack[\count($this->blockStack) - 1]) ? $this->blockStack[\count($this->blockStack) - 1] : null; + return $this->blockStack[\count($this->blockStack) - 1] ?? null; } public function popBlockStack(): void diff --git a/src/Profiler/Dumper/BlackfireDumper.php b/src/Profiler/Dumper/BlackfireDumper.php index 3fab5db1f..03abe0fa0 100644 --- a/src/Profiler/Dumper/BlackfireDumper.php +++ b/src/Profiler/Dumper/BlackfireDumper.php @@ -28,13 +28,13 @@ final class BlackfireDumper $str = << $values) { - $str .= "{$name}//{$values['ct']} {$values['wt']} {$values['mu']} {$values['pmu']}\n"; + $str .= "$name//{$values['ct']} {$values['wt']} {$values['mu']} {$values['pmu']}\n"; } return $str; diff --git a/src/Test/NodeTestCase.php b/src/Test/NodeTestCase.php index 646402417..3b8b2c86c 100644 --- a/src/Test/NodeTestCase.php +++ b/src/Test/NodeTestCase.php @@ -53,7 +53,7 @@ abstract class NodeTestCase extends TestCase protected function getVariableGetter($name, $line = false) { - $line = $line > 0 ? "// line {$line}\n" : ''; + $line = $line > 0 ? "// line $line\n" : ''; return sprintf('%s($context["%s"] ?? null)', $line, $name); } diff --git a/src/TokenParser/ForTokenParser.php b/src/TokenParser/ForTokenParser.php index b6d3b4e41..bac8ba2da 100644 --- a/src/TokenParser/ForTokenParser.php +++ b/src/TokenParser/ForTokenParser.php @@ -52,12 +52,11 @@ final class ForTokenParser extends AbstractTokenParser $keyTarget = $targets->getNode(0); $keyTarget = new AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine()); $valueTarget = $targets->getNode(1); - $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); } else { $keyTarget = new AssignNameExpression('_key', $lineno); $valueTarget = $targets->getNode(0); - $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); } + $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); return new ForNode($keyTarget, $valueTarget, $seq, null, $body, $else, $lineno, $this->getTag()); }