diff --git a/src/Extension/AbstractExtension.php b/src/Extension/AbstractExtension.php index 422925f31..a1b083b68 100644 --- a/src/Extension/AbstractExtension.php +++ b/src/Extension/AbstractExtension.php @@ -40,6 +40,6 @@ abstract class AbstractExtension implements ExtensionInterface public function getOperators() { - return []; + return [[], []]; } } diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index d0e1dccc7..7383a68a4 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -1516,7 +1516,7 @@ final class CoreExtension extends AbstractExtension throw new RuntimeError(\sprintf('The "batch" filter expects a sequence/mapping or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items))); } - $size = ceil($size); + $size = (int) ceil($size); $result = array_chunk(self::toArray($items, $preserveKeys), $size, $preserveKeys); diff --git a/src/Extension/EscaperExtension.php b/src/Extension/EscaperExtension.php index b3ebf65fe..f453ada93 100644 --- a/src/Extension/EscaperExtension.php +++ b/src/Extension/EscaperExtension.php @@ -119,7 +119,7 @@ final class EscaperExtension extends AbstractExtension * Defines a new escaper to be used via the escape filter. * * @param string $strategy The strategy name that should be used as a strategy in the escape call - * @param callable(Environment, string, string) $callable A valid PHP callable + * @param callable(Environment, string, string): string $callable A valid PHP callable * * @deprecated since Twig 3.10 */ @@ -142,7 +142,7 @@ final class EscaperExtension extends AbstractExtension /** * Gets all defined escapers. * - * @return array An array of escapers + * @return array An array of escapers * * @deprecated since Twig 3.10 */ diff --git a/src/Extension/ExtensionInterface.php b/src/Extension/ExtensionInterface.php index ab9c2c37c..10a42b6b1 100644 --- a/src/Extension/ExtensionInterface.php +++ b/src/Extension/ExtensionInterface.php @@ -12,8 +12,7 @@ namespace Twig\Extension; use Twig\ExpressionParser; -use Twig\Node\Expression\Binary\AbstractBinary; -use Twig\Node\Expression\Unary\AbstractUnary; +use Twig\Node\Expression\AbstractExpression; use Twig\NodeVisitor\NodeVisitorInterface; use Twig\TokenParser\TokenParserInterface; use Twig\TwigFilter; @@ -68,8 +67,8 @@ interface ExtensionInterface * @return array First array of unary operators, second array of binary operators * * @psalm-return array{ - * array}>, - * array, associativity: ExpressionParser::OPERATOR_*}> + * array}>, + * array, associativity: ExpressionParser::OPERATOR_*}> * } */ public function getOperators(); diff --git a/src/ExtensionSet.php b/src/ExtensionSet.php index 34b600063..8b59a13e1 100644 --- a/src/ExtensionSet.php +++ b/src/ExtensionSet.php @@ -15,6 +15,7 @@ use Twig\Error\RuntimeError; use Twig\Extension\ExtensionInterface; use Twig\Extension\GlobalsInterface; use Twig\Extension\StagingExtension; +use Twig\Node\Expression\AbstractExpression; use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Node\Expression\Unary\AbstractUnary; use Twig\NodeVisitor\NodeVisitorInterface; @@ -39,9 +40,9 @@ final class ExtensionSet private $tests; /** @var array */ private $functions; - /** @var array}> */ + /** @var array}> */ private $unaryOperators; - /** @var array, associativity: ExpressionParser::OPERATOR_*}> */ + /** @var array, associativity: ExpressionParser::OPERATOR_*}> */ private $binaryOperators; /** @var array */ private $globals; @@ -391,7 +392,7 @@ final class ExtensionSet } /** - * @return array}> + * @return array}> */ public function getUnaryOperators(): array { @@ -403,7 +404,7 @@ final class ExtensionSet } /** - * @return array, associativity: ExpressionParser::OPERATOR_*}> + * @return array, associativity: ExpressionParser::OPERATOR_*}> */ public function getBinaryOperators(): array { diff --git a/src/Node/Expression/CallExpression.php b/src/Node/Expression/CallExpression.php index 997e8dc9f..cd81df47a 100644 --- a/src/Node/Expression/CallExpression.php +++ b/src/Node/Expression/CallExpression.php @@ -279,7 +279,7 @@ abstract class CallExpression extends AbstractExpression $isPhpVariadic = false; if ($isVariadic) { $argument = end($parameters); - $isArray = $argument && $argument->hasType() && 'array' === $argument->getType()->getName(); + $isArray = $argument && $argument->hasType() && $argument->getType() instanceof \ReflectionNamedType && 'array' === $argument->getType()->getName(); if ($isArray && $argument->isDefaultValueAvailable() && [] === $argument->getDefaultValue()) { array_pop($parameters); } elseif ($argument && $argument->isVariadic()) { diff --git a/src/Node/Expression/MethodCallExpression.php b/src/Node/Expression/MethodCallExpression.php index 6fa1c3f9e..01806f91d 100644 --- a/src/Node/Expression/MethodCallExpression.php +++ b/src/Node/Expression/MethodCallExpression.php @@ -46,7 +46,9 @@ class MethodCallExpression extends AbstractExpression ->raw(', [') ; $first = true; - foreach ($this->getNode('arguments')->getKeyValuePairs() as $pair) { + /** @var ArrayExpression */ + $args = $this->getNode('arguments'); + foreach ($args->getKeyValuePairs() as $pair) { if (!$first) { $compiler->raw(', '); } diff --git a/src/Node/PrintNode.php b/src/Node/PrintNode.php index bdc738301..da442d852 100644 --- a/src/Node/PrintNode.php +++ b/src/Node/PrintNode.php @@ -31,10 +31,13 @@ class PrintNode extends Node implements NodeOutputInterface public function compile(Compiler $compiler): void { + /** @var AbstractExpression */ + $expr = $this->getNode('expr'); + $compiler ->addDebugInfo($this) - ->write($this->getNode('expr')->isGenerator() ? 'yield from ' : 'yield ') - ->subcompile($this->getNode('expr')) + ->write($expr->isGenerator() ? 'yield from ' : 'yield ') + ->subcompile($expr) ->raw(";\n") ; } diff --git a/src/Runtime/EscaperRuntime.php b/src/Runtime/EscaperRuntime.php index 433a0250c..4df834306 100644 --- a/src/Runtime/EscaperRuntime.php +++ b/src/Runtime/EscaperRuntime.php @@ -17,6 +17,7 @@ use Twig\Markup; final class EscaperRuntime implements RuntimeExtensionInterface { + /** @var array */ private $escapers = []; /** @internal */ @@ -36,7 +37,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface * Defines a new escaper to be used via the escape filter. * * @param string $strategy The strategy name that should be used as a strategy in the escape call - * @param callable(string $string, string $charset) $callable A valid PHP callable + * @param callable(string $string, string $charset): string $callable A valid PHP callable */ public function setEscaper($strategy, callable $callable) { @@ -46,7 +47,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface /** * Gets all defined escapers. * - * @return array An array of escapers + * @return array An array of escapers */ public function getEscapers() { diff --git a/src/Test/NodeTestCase.php b/src/Test/NodeTestCase.php index e6a954948..4046f08cd 100644 --- a/src/Test/NodeTestCase.php +++ b/src/Test/NodeTestCase.php @@ -53,7 +53,11 @@ abstract class NodeTestCase extends TestCase protected function getEnvironment() { - return $this->currentEnv = new Environment(new ArrayLoader()); + if (!$this->currentEnv) { + $this->currentEnv = new Environment(new ArrayLoader()); + } + + return $this->currentEnv; } protected function getVariableGetter($name, $line = false) diff --git a/src/Util/DeprecationCollector.php b/src/Util/DeprecationCollector.php index 378b666bd..ad5310617 100644 --- a/src/Util/DeprecationCollector.php +++ b/src/Util/DeprecationCollector.php @@ -60,6 +60,8 @@ final class DeprecationCollector if (\E_USER_DEPRECATED === $type) { $deprecations[] = $msg; } + + return false; }); foreach ($iterator as $name => $contents) {