From ac0f512553fab5a685aa0ed1e357d20a644b81bf Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 20 Sep 2019 14:07:06 +0200 Subject: [PATCH] [3.0] remove the most blocking return types --- composer.json | 2 +- src/Extension/AbstractExtension.php | 12 ++++++------ src/Extension/ExtensionInterface.php | 12 ++++++------ src/Extension/ProfilerExtension.php | 10 ++++++++-- src/Loader/FilesystemLoader.php | 10 ++++++++-- src/Loader/LoaderInterface.php | 5 ++++- src/Node/Expression/Binary/SpaceshipBinary.php | 2 +- src/Node/Expression/FunctionExpression.php | 2 +- src/Node/Node.php | 12 ++++++------ src/NodeVisitor/AbstractNodeVisitor.php | 4 ++-- src/Profiler/Profile.php | 2 +- src/TokenParser/TokenParserInterface.php | 8 ++++++-- 12 files changed, 50 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index 0176026b1..e2a092a31 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ } ], "require": { - "php": "^7.1.3", + "php": "^7.2.9", "symfony/polyfill-mbstring": "^1.3", "symfony/polyfill-ctype": "^1.8" }, diff --git a/src/Extension/AbstractExtension.php b/src/Extension/AbstractExtension.php index baca4233a..422925f31 100644 --- a/src/Extension/AbstractExtension.php +++ b/src/Extension/AbstractExtension.php @@ -13,32 +13,32 @@ namespace Twig\Extension; abstract class AbstractExtension implements ExtensionInterface { - public function getTokenParsers(): array + public function getTokenParsers() { return []; } - public function getNodeVisitors(): array + public function getNodeVisitors() { return []; } - public function getFilters(): array + public function getFilters() { return []; } - public function getTests(): array + public function getTests() { return []; } - public function getFunctions(): array + public function getFunctions() { return []; } - public function getOperators(): array + public function getOperators() { return []; } diff --git a/src/Extension/ExtensionInterface.php b/src/Extension/ExtensionInterface.php index 72017cd8e..75fa237e1 100644 --- a/src/Extension/ExtensionInterface.php +++ b/src/Extension/ExtensionInterface.php @@ -29,40 +29,40 @@ interface ExtensionInterface * * @return TokenParserInterface[] */ - public function getTokenParsers(): array; + public function getTokenParsers(); /** * Returns the node visitor instances to add to the existing list. * * @return NodeVisitorInterface[] */ - public function getNodeVisitors(): array; + public function getNodeVisitors(); /** * Returns a list of filters to add to the existing list. * * @return TwigFilter[] */ - public function getFilters(): array; + public function getFilters(); /** * Returns a list of tests to add to the existing list. * * @return TwigTest[] */ - public function getTests(): array; + public function getTests(); /** * Returns a list of functions to add to the existing list. * * @return TwigFunction[] */ - public function getFunctions(): array; + public function getFunctions(); /** * Returns a list of operators to add to the existing list. * * @return array First array of unary operators, second array of binary operators */ - public function getOperators(): array; + public function getOperators(); } diff --git a/src/Extension/ProfilerExtension.php b/src/Extension/ProfilerExtension.php index c3b20465d..d8125b2d3 100644 --- a/src/Extension/ProfilerExtension.php +++ b/src/Extension/ProfilerExtension.php @@ -23,13 +23,19 @@ class ProfilerExtension extends AbstractExtension $this->actives[] = $profile; } - public function enter(Profile $profile): void + /** + * @return void + */ + public function enter(Profile $profile) { $this->actives[0]->addProfile($profile); array_unshift($this->actives, $profile); } - public function leave(Profile $profile): void + /** + * @return void + */ + public function leave(Profile $profile) { $profile->leave(); array_shift($this->actives); diff --git a/src/Loader/FilesystemLoader.php b/src/Loader/FilesystemLoader.php index 8b0b914cc..e55943d35 100644 --- a/src/Loader/FilesystemLoader.php +++ b/src/Loader/FilesystemLoader.php @@ -139,7 +139,10 @@ class FilesystemLoader implements LoaderInterface return $path; } - public function exists(string $name): bool + /** + * @return bool + */ + public function exists(string $name) { $name = $this->normalizeName($name); @@ -160,7 +163,10 @@ class FilesystemLoader implements LoaderInterface return filemtime($path) < $time; } - protected function findTemplate(string $name, bool $throw = true): ?string + /** + * @return string|null + */ + protected function findTemplate(string $name, bool $throw = true) { $name = $this->normalizeName($name); diff --git a/src/Loader/LoaderInterface.php b/src/Loader/LoaderInterface.php index 5bccbef80..fec7e85ff 100644 --- a/src/Loader/LoaderInterface.php +++ b/src/Loader/LoaderInterface.php @@ -42,5 +42,8 @@ interface LoaderInterface */ public function isFresh(string $name, int $time): bool; - public function exists(string $name): bool; + /** + * @return bool + */ + public function exists(string $name); } diff --git a/src/Node/Expression/Binary/SpaceshipBinary.php b/src/Node/Expression/Binary/SpaceshipBinary.php index 5245e4051..ae5a4a493 100644 --- a/src/Node/Expression/Binary/SpaceshipBinary.php +++ b/src/Node/Expression/Binary/SpaceshipBinary.php @@ -15,7 +15,7 @@ use Twig\Compiler; class SpaceshipBinary extends AbstractBinary { - public function operator(Compiler $compiler) + public function operator(Compiler $compiler): Compiler { return $compiler->raw('<=>'); } diff --git a/src/Node/Expression/FunctionExpression.php b/src/Node/Expression/FunctionExpression.php index 765203f47..71269775c 100644 --- a/src/Node/Expression/FunctionExpression.php +++ b/src/Node/Expression/FunctionExpression.php @@ -21,7 +21,7 @@ class FunctionExpression extends CallExpression parent::__construct(['arguments' => $arguments], ['name' => $name, 'is_defined_test' => false], $lineno); } - public function compile(Compiler $compiler): void + public function compile(Compiler $compiler) { $name = $this->getAttribute('name'); $function = $compiler->getEnvironment()->getFunction($name); diff --git a/src/Node/Node.php b/src/Node/Node.php index 86bcdc514..6895a21d7 100644 --- a/src/Node/Node.php +++ b/src/Node/Node.php @@ -77,7 +77,10 @@ class Node implements \Countable, \IteratorAggregate return implode("\n", $repr); } - public function compile(Compiler $compiler): void + /** + * @return void + */ + public function compile(Compiler $compiler) { foreach ($this->nodes as $node) { $node->compile($compiler); @@ -123,10 +126,7 @@ class Node implements \Countable, \IteratorAggregate return isset($this->nodes[$name]); } - /** - * @param string|int $name - */ - public function getNode($name): self + public function getNode(string $name): self { if (!isset($this->nodes[$name])) { throw new \LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, \get_class($this))); @@ -150,7 +150,7 @@ class Node implements \Countable, \IteratorAggregate return \count($this->nodes); } - public function getIterator() + public function getIterator(): \Traversable { return new \ArrayIterator($this->nodes); } diff --git a/src/NodeVisitor/AbstractNodeVisitor.php b/src/NodeVisitor/AbstractNodeVisitor.php index 41af6159c..d7036ae55 100644 --- a/src/NodeVisitor/AbstractNodeVisitor.php +++ b/src/NodeVisitor/AbstractNodeVisitor.php @@ -38,12 +38,12 @@ abstract class AbstractNodeVisitor implements NodeVisitorInterface * * @return Node The modified node */ - abstract protected function doEnterNode(Node $node, Environment $env): Node; + abstract protected function doEnterNode(Node $node, Environment $env); /** * Called after child nodes are visited. * * @return Node|null The modified node or null if the node must be removed */ - abstract protected function doLeaveNode(Node $node, Environment $env): ?Node; + abstract protected function doLeaveNode(Node $node, Environment $env); } diff --git a/src/Profiler/Profile.php b/src/Profiler/Profile.php index f553d7196..36b39e1ea 100644 --- a/src/Profiler/Profile.php +++ b/src/Profiler/Profile.php @@ -148,7 +148,7 @@ final class Profile implements \IteratorAggregate, \Serializable $this->enter(); } - public function getIterator() + public function getIterator(): \Traversable { return new \ArrayIterator($this->profiles); } diff --git a/src/TokenParser/TokenParserInterface.php b/src/TokenParser/TokenParserInterface.php index 50d1d424e..bb8db3e5c 100644 --- a/src/TokenParser/TokenParserInterface.php +++ b/src/TokenParser/TokenParserInterface.php @@ -31,12 +31,16 @@ interface TokenParserInterface /** * Parses a token and returns a node. * + * @return Node + * * @throws SyntaxError */ - public function parse(Token $token): Node; + public function parse(Token $token); /** * Gets the tag name associated with this token parser. + * + * @return string */ - public function getTag(): string; + public function getTag(); }