Some code style fixes

This commit is contained in:
Den
2021-04-16 18:50:36 +03:00
committed by Fabien Potencier
parent 32d72de188
commit 17c6371fb5
10 changed files with 13 additions and 14 deletions
+3 -1
View File
@@ -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());
+2 -3
View File
@@ -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;
}
-1
View File
@@ -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));
}
+1 -1
View File
@@ -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] ?? [];
}
/**
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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
+2 -2
View File
@@ -28,13 +28,13 @@ final class BlackfireDumper
$str = <<<EOF
file-format: BlackfireProbe
cost-dimensions: wt mu pmu
request-start: {$start}
request-start: $start
EOF;
foreach ($data as $name => $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;
+1 -1
View File
@@ -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);
}
+1 -2
View File
@@ -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());
}