added some type hints on constructors

This commit is contained in:
Fabien Potencier
2019-03-16 13:25:13 +01:00
parent 241f95cb25
commit 1dead73882
52 changed files with 53 additions and 53 deletions
+1 -1
View File
@@ -61,7 +61,7 @@ class Error extends \Exception
* @param Source|string|null $source The source context where the error occurred
* @param \Exception $previous The previous exception
*/
public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null, $autoGuess = true)
public function __construct(string $message, int $lineno = -1, $source = null, \Exception $previous = null, bool $autoGuess = true)
{
parent::__construct('', 0, $previous);
+1 -1
View File
@@ -26,7 +26,7 @@ namespace Twig\Error;
*/
class LoaderError extends Error
{
public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null)
public function __construct(string $message, int $lineno = -1, $source = null, \Exception $previous = null)
{
parent::__construct($message, $lineno, $source, $previous, false);
}
+1 -1
View File
@@ -34,7 +34,7 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source
* @param string|array $paths A path or an array of paths where to look for templates
* @param string|null $rootPath The root path common to all relative paths (null for getcwd())
*/
public function __construct($paths = [], $rootPath = null)
public function __construct($paths = [], string $rootPath = null)
{
$this->rootPath = (null === $rootPath ? getcwd() : $rootPath).\DIRECTORY_SEPARATOR;
if (false !== $realPath = realpath($rootPath)) {
+1 -1
View File
@@ -26,7 +26,7 @@ use Twig\Compiler;
*/
class AutoEscapeNode extends Node
{
public function __construct($value, Node $body, $lineno, $tag = 'autoescape')
public function __construct($value, Node $body, int $lineno, string $tag = 'autoescape')
{
parent::__construct(['body' => $body], ['value' => $value], $lineno, $tag);
}
+1 -1
View File
@@ -21,7 +21,7 @@ use Twig\Compiler;
*/
class BlockNode extends Node
{
public function __construct($name, Node $body, $lineno, $tag = null)
public function __construct(string $name, Node $body, int $lineno, string $tag = null)
{
parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag);
}
+1 -1
View File
@@ -21,7 +21,7 @@ use Twig\Compiler;
*/
class BlockReferenceNode extends Node implements NodeOutputInterface
{
public function __construct($name, $lineno, $tag = null)
public function __construct(string $name, int $lineno, string $tag = null)
{
parent::__construct([], ['name' => $name], $lineno, $tag);
}
+1 -1
View File
@@ -22,7 +22,7 @@ use Twig\Node\Expression\ConstantExpression;
*/
class DeprecatedNode extends Node
{
public function __construct(AbstractExpression $expr, $lineno, $tag = null)
public function __construct(AbstractExpression $expr, int $lineno, string $tag = null)
{
parent::__construct(['expr' => $expr], [], $lineno, $tag);
}
+1 -1
View File
@@ -21,7 +21,7 @@ use Twig\Node\Expression\AbstractExpression;
*/
class DoNode extends Node
{
public function __construct(AbstractExpression $expr, $lineno, $tag = null)
public function __construct(AbstractExpression $expr, int $lineno, string $tag = null)
{
parent::__construct(['expr' => $expr], [], $lineno, $tag);
}
+1 -1
View File
@@ -23,7 +23,7 @@ use Twig\Node\Expression\ConstantExpression;
class EmbedNode extends IncludeNode
{
// we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module)
public function __construct($name, $index, AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
public function __construct(string $name, int $index, AbstractExpression $variables = null, bool $only = false, bool $ignoreMissing = false, int $lineno, string $tag = null)
{
parent::__construct(new ConstantExpression('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag);
+1 -1
View File
@@ -17,7 +17,7 @@ class ArrayExpression extends AbstractExpression
{
private $index;
public function __construct(array $elements, $lineno)
public function __construct(array $elements, int $lineno)
{
parent::__construct($elements, [], $lineno);
@@ -18,7 +18,7 @@ use Twig\Node\Node;
abstract class AbstractBinary extends AbstractExpression
{
public function __construct(Node $left, Node $right, $lineno)
public function __construct(Node $left, Node $right, int $lineno)
{
parent::__construct(['left' => $left, 'right' => $right], [], $lineno);
}
@@ -22,7 +22,7 @@ use Twig\Node\Node;
*/
class BlockReferenceExpression extends AbstractExpression
{
public function __construct(Node $name, Node $template = null, $lineno, $tag = null)
public function __construct(Node $name, Node $template = null, int $lineno, string $tag = null)
{
$nodes = ['name' => $name];
if (null !== $template) {
@@ -16,7 +16,7 @@ use Twig\Compiler;
class ConditionalExpression extends AbstractExpression
{
public function __construct(AbstractExpression $expr1, AbstractExpression $expr2, AbstractExpression $expr3, $lineno)
public function __construct(AbstractExpression $expr1, AbstractExpression $expr2, AbstractExpression $expr3, int $lineno)
{
parent::__construct(['expr1' => $expr1, 'expr2' => $expr2, 'expr3' => $expr3], [], $lineno);
}
+1 -1
View File
@@ -16,7 +16,7 @@ use Twig\Compiler;
class ConstantExpression extends AbstractExpression
{
public function __construct($value, $lineno)
public function __construct($value, int $lineno)
{
parent::__construct([], ['value' => $value], $lineno);
}
+1 -1
View File
@@ -29,7 +29,7 @@ use Twig\Node\Node;
*/
class DefaultFilter extends FilterExpression
{
public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, $lineno, $tag = null)
public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, string $tag = null)
{
$default = new FilterExpression($node, new ConstantExpression('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine());
+1 -1
View File
@@ -17,7 +17,7 @@ use Twig\Node\Node;
class FilterExpression extends CallExpression
{
public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, $lineno, $tag = null)
public function __construct(Node $node, ConstantExpression $filterName, Node $arguments, int $lineno, string $tag = null)
{
parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag);
}
+1 -1
View File
@@ -16,7 +16,7 @@ use Twig\Node\Node;
class FunctionExpression extends CallExpression
{
public function __construct($name, Node $arguments, $lineno)
public function __construct(string $name, Node $arguments, int $lineno)
{
parent::__construct(['arguments' => $arguments], ['name' => $name, 'is_defined_test' => false], $lineno);
}
+1 -1
View File
@@ -18,7 +18,7 @@ use Twig\Template;
class GetAttrExpression extends AbstractExpression
{
public function __construct(AbstractExpression $node, AbstractExpression $attribute, AbstractExpression $arguments = null, $type, $lineno)
public function __construct(AbstractExpression $node, AbstractExpression $attribute, AbstractExpression $arguments = null, string $type, int $lineno)
{
$nodes = ['node' => $node, 'attribute' => $attribute];
if (null !== $arguments) {
+1 -1
View File
@@ -15,7 +15,7 @@ use Twig\Compiler;
class MethodCallExpression extends AbstractExpression
{
public function __construct(AbstractExpression $node, $method, ArrayExpression $arguments, $lineno)
public function __construct(AbstractExpression $node, string $method, ArrayExpression $arguments, int $lineno)
{
parent::__construct(['node' => $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false], $lineno);
+1 -1
View File
@@ -22,7 +22,7 @@ class NameExpression extends AbstractExpression
'_charset' => '$this->env->getCharset()',
];
public function __construct($name, $lineno)
public function __construct(string $name, int $lineno)
{
parent::__construct([], ['name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false], $lineno);
}
@@ -20,7 +20,7 @@ use Twig\Node\Node;
class NullCoalesceExpression extends ConditionalExpression
{
public function __construct(Node $left, Node $right, $lineno)
public function __construct(Node $left, Node $right, int $lineno)
{
$test = new AndBinary(
new DefinedTest(clone $left, 'defined', new Node(), $left->getTemplateLine()),
+1 -1
View File
@@ -21,7 +21,7 @@ use Twig\Compiler;
*/
class ParentExpression extends AbstractExpression
{
public function __construct($name, $lineno, $tag = null)
public function __construct(string $name, int $lineno, string $tag = null)
{
parent::__construct([], ['output' => false, 'name' => $name], $lineno, $tag);
}
+1 -1
View File
@@ -15,7 +15,7 @@ use Twig\Compiler;
class TempNameExpression extends AbstractExpression
{
public function __construct($name, $lineno)
public function __construct(string $name, int $lineno)
{
parent::__construct([], ['name' => $name], $lineno);
}
+1 -1
View File
@@ -34,7 +34,7 @@ use Twig\Node\Node;
*/
class DefinedTest extends TestExpression
{
public function __construct(Node $node, $name, Node $arguments = null, $lineno)
public function __construct(Node $node, string $name, Node $arguments = null, int $lineno)
{
if ($node instanceof NameExpression) {
$node->setAttribute('is_defined_test', true);
+1 -1
View File
@@ -16,7 +16,7 @@ use Twig\Node\Node;
class TestExpression extends CallExpression
{
public function __construct(Node $node, $name, Node $arguments = null, $lineno)
public function __construct(Node $node, string $name, Node $arguments = null, int $lineno)
{
$nodes = ['node' => $node];
if (null !== $arguments) {
+1 -1
View File
@@ -18,7 +18,7 @@ use Twig\Node\Node;
abstract class AbstractUnary extends AbstractExpression
{
public function __construct(Node $node, $lineno)
public function __construct(Node $node, int $lineno)
{
parent::__construct(['node' => $node], [], $lineno);
}
+1 -1
View File
@@ -20,7 +20,7 @@ use Twig\Compiler;
*/
class FlushNode extends Node
{
public function __construct($lineno, $tag)
public function __construct(int $lineno, string $tag)
{
parent::__construct([], [], $lineno, $tag);
}
+1 -1
View File
@@ -20,7 +20,7 @@ use Twig\Compiler;
*/
class ForLoopNode extends Node
{
public function __construct($lineno, $tag = null)
public function __construct(int $lineno, string $tag = null)
{
parent::__construct([], ['with_loop' => false, 'ifexpr' => false, 'else' => false], $lineno, $tag);
}
+1 -1
View File
@@ -25,7 +25,7 @@ class ForNode extends Node
{
private $loop;
public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, AbstractExpression $ifexpr = null, Node $body, Node $else = null, $lineno, $tag = null)
public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, AbstractExpression $ifexpr = null, Node $body, Node $else = null, int $lineno, string $tag = null)
{
$body = new Node([$body, $this->loop = new ForLoopNode($lineno, $tag)]);
+1 -1
View File
@@ -21,7 +21,7 @@ use Twig\Compiler;
*/
class IfNode extends Node
{
public function __construct(Node $tests, Node $else = null, $lineno, $tag = null)
public function __construct(Node $tests, Node $else = null, int $lineno, string $tag = null)
{
$nodes = ['tests' => $tests];
if (null !== $else) {
+1 -1
View File
@@ -22,7 +22,7 @@ use Twig\Node\Expression\NameExpression;
*/
class ImportNode extends Node
{
public function __construct(AbstractExpression $expr, AbstractExpression $var, $lineno, $tag = null)
public function __construct(AbstractExpression $expr, AbstractExpression $var, int $lineno, string $tag = null)
{
parent::__construct(['expr' => $expr, 'var' => $var], [], $lineno, $tag);
}
+1 -1
View File
@@ -22,7 +22,7 @@ use Twig\Node\Expression\AbstractExpression;
*/
class IncludeNode extends Node implements NodeOutputInterface
{
public function __construct(AbstractExpression $expr, AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null)
public function __construct(AbstractExpression $expr, AbstractExpression $variables = null, bool $only = false, bool $ignoreMissing = false, int $lineno, string $tag = null)
{
$nodes = ['expr' => $expr];
if (null !== $variables) {
+1 -1
View File
@@ -23,7 +23,7 @@ class MacroNode extends Node
{
const VARARGS_NAME = 'varargs';
public function __construct($name, Node $body, Node $arguments, $lineno, $tag = null)
public function __construct(string $name, Node $body, Node $arguments, int $lineno, string $tag = null)
{
foreach ($arguments as $argumentName => $argument) {
if (self::VARARGS_NAME === $argumentName) {
+1 -1
View File
@@ -39,7 +39,7 @@ class Node implements \Countable, \IteratorAggregate
* @param int $lineno The line number
* @param string $tag The tag name associated with the Node
*/
public function __construct(array $nodes = [], array $attributes = [], $lineno = 0, $tag = null)
public function __construct(array $nodes = [], array $attributes = [], int $lineno = 0, string $tag = null)
{
foreach ($nodes as $name => $node) {
if (!$node instanceof self) {
+1 -1
View File
@@ -22,7 +22,7 @@ use Twig\Node\Expression\AbstractExpression;
*/
class PrintNode extends Node implements NodeOutputInterface
{
public function __construct(AbstractExpression $expr, $lineno, $tag = null)
public function __construct(AbstractExpression $expr, int $lineno, string $tag = null)
{
parent::__construct(['expr' => $expr], [], $lineno, $tag);
}
+1 -1
View File
@@ -20,7 +20,7 @@ use Twig\Compiler;
*/
class SandboxNode extends Node
{
public function __construct(Node $body, $lineno, $tag = null)
public function __construct(Node $body, int $lineno, string $tag = null)
{
parent::__construct(['body' => $body], [], $lineno, $tag);
}
+1 -1
View File
@@ -21,7 +21,7 @@ use Twig\Node\Expression\ConstantExpression;
*/
class SetNode extends Node implements NodeCaptureInterface
{
public function __construct($capture, Node $names, Node $values, $lineno, $tag = null)
public function __construct(bool $capture, Node $names, Node $values, int $lineno, string $tag = null)
{
parent::__construct(['names' => $names, 'values' => $values], ['capture' => $capture, 'safe' => false], $lineno, $tag);
+1 -1
View File
@@ -24,7 +24,7 @@ use Twig\Compiler;
*/
class SpacelessNode extends Node implements NodeOutputInterface
{
public function __construct(Node $body, $lineno, $tag = 'spaceless')
public function __construct(Node $body, int $lineno, string $tag = 'spaceless')
{
parent::__construct(['body' => $body], [], $lineno, $tag);
}
+1 -1
View File
@@ -21,7 +21,7 @@ use Twig\Compiler;
*/
class TextNode extends Node implements NodeOutputInterface
{
public function __construct($data, $lineno)
public function __construct(string $data, int $lineno)
{
parent::__construct([], ['data' => $data], $lineno);
}
+2 -2
View File
@@ -20,14 +20,14 @@ use Twig\Compiler;
*/
class WithNode extends Node
{
public function __construct(Node $body, Node $variables = null, $only = false, $lineno, $tag = null)
public function __construct(Node $body, Node $variables = null, bool $only = false, int $lineno, string $tag = null)
{
$nodes = ['body' => $body];
if (null !== $variables) {
$nodes['variables'] = $variables;
}
parent::__construct($nodes, ['only' => (bool) $only], $lineno, $tag);
parent::__construct($nodes, ['only' => $only], $lineno, $tag);
}
public function compile(Compiler $compiler)
+1 -1
View File
@@ -51,7 +51,7 @@ final class OptimizerNodeVisitor extends AbstractNodeVisitor
/**
* @param int $optimizers The optimizer mode
*/
public function __construct($optimizers = -1)
public function __construct(int $optimizers = -1)
{
if (!\is_int($optimizers) || $optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_VAR_ACCESS)) {
throw new \InvalidArgumentException(sprintf('Optimizer mode "%s" is not valid.', $optimizers));
+1 -1
View File
@@ -21,7 +21,7 @@ use Twig\Node\Node;
*/
class EnterProfileNode extends Node
{
public function __construct($extensionName, $type, $name, $varName)
public function __construct(string $extensionName, string $type, string $name, string $varName)
{
parent::__construct([], ['extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName]);
}
+1 -1
View File
@@ -21,7 +21,7 @@ use Twig\Node\Node;
*/
class LeaveProfileNode extends Node
{
public function __construct($varName)
public function __construct(string $varName)
{
parent::__construct([], ['var_name' => $varName]);
}
@@ -29,7 +29,7 @@ final class ProfilerNodeVisitor extends AbstractNodeVisitor
{
private $extensionName;
public function __construct($extensionName)
public function __construct(string $extensionName)
{
$this->extensionName = $extensionName;
}
+1 -1
View File
@@ -30,7 +30,7 @@ class Profile implements \IteratorAggregate, \Serializable
private $ends = [];
private $profiles = [];
public function __construct($template = 'main', $type = self::ROOT, $name = 'main')
public function __construct(string $template = 'main', string $type = self::ROOT, string $name = 'main')
{
if (__CLASS__ !== \get_class($this)) {
@trigger_error('Overriding '.__CLASS__.' is deprecated since Twig 2.4.0 and the class will be final in 3.0.', E_USER_DEPRECATED);
+1 -1
View File
@@ -23,7 +23,7 @@ class FactoryRuntimeLoader implements RuntimeLoaderInterface
/**
* @param array $map An array where keys are class names and values factory callables
*/
public function __construct($map = [])
public function __construct(array $map = [])
{
$this->map = $map;
}
@@ -20,7 +20,7 @@ class SecurityNotAllowedFilterError extends SecurityError
{
private $filterName;
public function __construct($message, $functionName, $lineno = -1, $filename = null, \Exception $previous = null)
public function __construct(string $message, string $functionName, int $lineno = -1, string $filename = null, \Exception $previous = null)
{
parent::__construct($message, $lineno, $filename, $previous);
$this->filterName = $functionName;
@@ -20,7 +20,7 @@ class SecurityNotAllowedFunctionError extends SecurityError
{
private $functionName;
public function __construct($message, $functionName, $lineno = -1, $filename = null, \Exception $previous = null)
public function __construct(string $message, string $functionName, int $lineno = -1, string $filename = null, \Exception $previous = null)
{
parent::__construct($message, $lineno, $filename, $previous);
$this->functionName = $functionName;
@@ -21,7 +21,7 @@ class SecurityNotAllowedMethodError extends SecurityError
private $className;
private $methodName;
public function __construct($message, $className, $methodName, $lineno = -1, $filename = null, \Exception $previous = null)
public function __construct(string $message, string $className, string $methodName, int $lineno = -1, string $filename = null, \Exception $previous = null)
{
parent::__construct($message, $lineno, $filename, $previous);
$this->className = $className;
@@ -21,7 +21,7 @@ class SecurityNotAllowedPropertyError extends SecurityError
private $className;
private $propertyName;
public function __construct($message, $className, $propertyName, $lineno = -1, $filename = null, \Exception $previous = null)
public function __construct(string $message, string $className, string $propertyName, int $lineno = -1, string $filename = null, \Exception $previous = null)
{
parent::__construct($message, $lineno, $filename, $previous);
$this->className = $className;
+1 -1
View File
@@ -20,7 +20,7 @@ class SecurityNotAllowedTagError extends SecurityError
{
private $tagName;
public function __construct($message, $tagName, $lineno = -1, $filename = null, \Exception $previous = null)
public function __construct(string $message, string $tagName, int $lineno = -1, string $filename = null, \Exception $previous = null)
{
parent::__construct($message, $lineno, $filename, $previous);
$this->tagName = $tagName;
+1 -1
View File
@@ -29,7 +29,7 @@ final class WithTokenParser extends AbstractTokenParser
$only = false;
if (!$stream->test(/* Token::BLOCK_END_TYPE */ 3)) {
$variables = $this->parser->getExpressionParser()->parseExpression();
$only = $stream->nextIf(/* Token::NAME_TYPE */ 5, 'only');
$only = (bool) $stream->nextIf(/* Token::NAME_TYPE */ 5, 'only');
}
$stream->expect(/* Token::BLOCK_END_TYPE */ 3);