mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-24 16:26:27 +00:00
Some code style fixes
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user