diff --git a/src/ExpressionParser.php b/src/ExpressionParser.php index 73bdbc73b..38cbdd8a2 100644 --- a/src/ExpressionParser.php +++ b/src/ExpressionParser.php @@ -27,6 +27,8 @@ use Twig\Node\Expression\Unary\NegUnary; use Twig\Node\Expression\Unary\NotUnary; use Twig\Node\Expression\Unary\PosUnary; use Twig\Node\Node; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\TestExpression; /** * Parses expressions. @@ -88,7 +90,7 @@ class ExpressionParser return $expr; } - private function getPrimary() + private function getPrimary(): AbstractExpression { $token = $this->parser->getCurrentToken(); @@ -110,7 +112,7 @@ class ExpressionParser return $this->parsePrimaryExpression(); } - private function parseConditionalExpression($expr) + private function parseConditionalExpression($expr): AbstractExpression { while ($this->parser->getStream()->nextIf(/* Token::PUNCTUATION_TYPE */ 9, '?')) { if (!$this->parser->getStream()->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ':')) { @@ -131,12 +133,12 @@ class ExpressionParser return $expr; } - private function isUnary(Token $token) + private function isUnary(Token $token): bool { return $token->test(/* Token::OPERATOR_TYPE */ 8) && isset($this->unaryOperators[$token->getValue()]); } - private function isBinary(Token $token) + private function isBinary(Token $token): bool { return $token->test(/* Token::OPERATOR_TYPE */ 8) && isset($this->binaryOperators[$token->getValue()]); } @@ -598,12 +600,12 @@ class ExpressionParser return new Node($targets); } - private function parseNotTestExpression(Node $node) + private function parseNotTestExpression(Node $node): NotUnary { return new NotUnary($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine()); } - private function parseTestExpression(Node $node) + private function parseTestExpression(Node $node): TestExpression { $stream = $this->parser->getStream(); list($name, $test) = $this->getTest($node->getTemplateLine()); @@ -617,7 +619,7 @@ class ExpressionParser return new $class($node, $name, $arguments, $this->parser->getCurrentToken()->getLine()); } - private function getTest($line) + private function getTest(int $line): array { $stream = $this->parser->getStream(); $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); @@ -643,7 +645,7 @@ class ExpressionParser throw $e; } - private function getTestNodeClass($test) + private function getTestNodeClass(TwigTest $test): string { if ($test->isDeprecated()) { $stream = $this->parser->getStream(); @@ -664,7 +666,7 @@ class ExpressionParser return $test->getNodeClass(); } - private function getFunctionNodeClass($name, $line) + private function getFunctionNodeClass(string $name, int $line): string { if (false === $function = $this->env->getFunction($name)) { $e = new SyntaxError(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext()); @@ -690,7 +692,7 @@ class ExpressionParser return $function->getNodeClass(); } - private function getFilterNodeClass($name, $line) + private function getFilterNodeClass(string $name, int $line): string { if (false === $filter = $this->env->getFilter($name)) { $e = new SyntaxError(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext()); @@ -717,7 +719,7 @@ class ExpressionParser } // checks that the node only contains "constant" elements - private function checkConstantExpression(Node $node) + private function checkConstantExpression(Node $node): bool { if (!($node instanceof ConstantExpression || $node instanceof ArrayExpression || $node instanceof NegUnary || $node instanceof PosUnary diff --git a/src/Node/Expression/BlockReferenceExpression.php b/src/Node/Expression/BlockReferenceExpression.php index d370229a9..839186dee 100644 --- a/src/Node/Expression/BlockReferenceExpression.php +++ b/src/Node/Expression/BlockReferenceExpression.php @@ -49,7 +49,7 @@ class BlockReferenceExpression extends AbstractExpression } } - private function compileTemplateCall(Compiler $compiler, $method) + private function compileTemplateCall(Compiler $compiler, string $method): Compiler { if (!$this->hasNode('template')) { $compiler->write('$this'); @@ -66,12 +66,11 @@ class BlockReferenceExpression extends AbstractExpression } $compiler->raw(sprintf('->%s', $method)); - $this->compileBlockArguments($compiler); - return $compiler; + return $this->compileBlockArguments($compiler); } - private function compileBlockArguments(Compiler $compiler) + private function compileBlockArguments(Compiler $compiler): Compiler { $compiler ->raw('(') diff --git a/src/Node/Expression/CallExpression.php b/src/Node/Expression/CallExpression.php index 59be15b21..69c505855 100644 --- a/src/Node/Expression/CallExpression.php +++ b/src/Node/Expression/CallExpression.php @@ -230,7 +230,7 @@ abstract class CallExpression extends AbstractExpression return strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], ['\\1_\\2', '\\1_\\2'], $name)); } - private function getCallableParameters($callable, $isVariadic) + private function getCallableParameters($callable, bool $isVariadic): array { list($r) = $this->reflectCallable($callable); if (null === $r) { diff --git a/src/NodeTraverser.php b/src/NodeTraverser.php index e4146fc0b..42cced4b4 100644 --- a/src/NodeTraverser.php +++ b/src/NodeTraverser.php @@ -59,7 +59,7 @@ final class NodeTraverser return $node; } - private function traverseForVisitor(NodeVisitorInterface $visitor, Node $node) + private function traverseForVisitor(NodeVisitorInterface $visitor, Node $node): Node { $node = $visitor->enterNode($node, $this->env); diff --git a/src/NodeVisitor/EscaperNodeVisitor.php b/src/NodeVisitor/EscaperNodeVisitor.php index df1704d12..940ef8b30 100644 --- a/src/NodeVisitor/EscaperNodeVisitor.php +++ b/src/NodeVisitor/EscaperNodeVisitor.php @@ -147,7 +147,7 @@ final class EscaperNodeVisitor extends AbstractNodeVisitor return $this->defaultStrategy ? $this->defaultStrategy : false; } - private function getEscaperFilter($type, Node $node) + private function getEscaperFilter(string $type, Node $node): FilterExpression { $line = $node->getTemplateLine(); $name = new ConstantExpression('escape', $line); diff --git a/src/NodeVisitor/OptimizerNodeVisitor.php b/src/NodeVisitor/OptimizerNodeVisitor.php index a829aa285..4bf7f7470 100644 --- a/src/NodeVisitor/OptimizerNodeVisitor.php +++ b/src/NodeVisitor/OptimizerNodeVisitor.php @@ -90,10 +90,8 @@ final class OptimizerNodeVisitor extends AbstractNodeVisitor * It replaces: * * * "echo $this->render(Parent)Block()" with "$this->display(Parent)Block()" - * - * @return Node */ - private function optimizePrintNode(Node $node, Environment $env) + private function optimizePrintNode(Node $node, Environment $env): Node { if (!$node instanceof PrintNode) { return $node; @@ -114,10 +112,8 @@ final class OptimizerNodeVisitor extends AbstractNodeVisitor /** * Removes "raw" filters. - * - * @return Node */ - private function optimizeRawFilter(Node $node, Environment $env) + private function optimizeRawFilter(Node $node, Environment $env): Node { if ($node instanceof FilterExpression && 'raw' == $node->getNode('filter')->getAttribute('value')) { return $node->getNode('node'); diff --git a/src/NodeVisitor/SafeAnalysisNodeVisitor.php b/src/NodeVisitor/SafeAnalysisNodeVisitor.php index d0b0539de..02a2af436 100644 --- a/src/NodeVisitor/SafeAnalysisNodeVisitor.php +++ b/src/NodeVisitor/SafeAnalysisNodeVisitor.php @@ -134,7 +134,7 @@ final class SafeAnalysisNodeVisitor extends AbstractNodeVisitor return $node; } - private function intersectSafe(array $a = null, array $b = null) + private function intersectSafe(array $a = null, array $b = null): array { if (null === $a || null === $b) { return []; diff --git a/src/NodeVisitor/SandboxNodeVisitor.php b/src/NodeVisitor/SandboxNodeVisitor.php index aa229564e..9fb432d68 100644 --- a/src/NodeVisitor/SandboxNodeVisitor.php +++ b/src/NodeVisitor/SandboxNodeVisitor.php @@ -110,7 +110,7 @@ final class SandboxNodeVisitor extends AbstractNodeVisitor return $node; } - private function wrapNode(Node $node, $name) + private function wrapNode(Node $node, string $name) { $expr = $node->getNode($name); if ($expr instanceof NameExpression || $expr instanceof GetAttrExpression) { @@ -118,7 +118,7 @@ final class SandboxNodeVisitor extends AbstractNodeVisitor } } - private function wrapArrayNode(Node $node, $name) + private function wrapArrayNode(Node $node, string $name) { $args = $node->getNode($name); foreach ($args as $name => $_) { diff --git a/src/Parser.php b/src/Parser.php index 89193d516..e93df8d0b 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -335,7 +335,7 @@ class Parser return $this->stream->getCurrent(); } - private function filterBodyNodes(Node $node, $nested = false) + private function filterBodyNodes(Node $node, bool $nested = false) { // check that the body does not contain non-empty output nodes if ( diff --git a/src/Profiler/Dumper/BaseDumper.php b/src/Profiler/Dumper/BaseDumper.php index d965dc754..1631987bb 100644 --- a/src/Profiler/Dumper/BaseDumper.php +++ b/src/Profiler/Dumper/BaseDumper.php @@ -31,7 +31,7 @@ abstract class BaseDumper abstract protected function formatTime(Profile $profile, $percent); - private function dumpProfile(Profile $profile, $prefix = '', $sibling = false) + private function dumpProfile(Profile $profile, $prefix = '', $sibling = false): string { if ($profile->isRoot()) { $this->root = $profile->getDuration(); diff --git a/src/Profiler/Dumper/BlackfireDumper.php b/src/Profiler/Dumper/BlackfireDumper.php index 05d937baf..f33342905 100644 --- a/src/Profiler/Dumper/BlackfireDumper.php +++ b/src/Profiler/Dumper/BlackfireDumper.php @@ -40,7 +40,7 @@ EOF; return $str; } - private function dumpChildren($parent, Profile $profile, &$data) + private function dumpChildren(string $parent, Profile $profile, &$data) { foreach ($profile as $p) { if ($p->isTemplate()) { @@ -53,7 +53,7 @@ EOF; } } - private function dumpProfile($edge, Profile $profile, &$data) + private function dumpProfile(string $edge, Profile $profile, &$data) { if (isset($data[$edge])) { ++$data[$edge]['ct']; diff --git a/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php b/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php index a5416004f..fcfcdd20f 100644 --- a/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php +++ b/src/Profiler/NodeVisitor/ProfilerNodeVisitor.php @@ -64,7 +64,7 @@ final class ProfilerNodeVisitor extends AbstractNodeVisitor return $node; } - private function getVarName() + private function getVarName(): string { return sprintf('__internal_%s', hash('sha256', $this->extensionName)); }