diff --git a/src/ExpressionParser.php b/src/ExpressionParser.php index 6ac11cb56..f00e780a5 100644 --- a/src/ExpressionParser.php +++ b/src/ExpressionParser.php @@ -96,10 +96,7 @@ class ExpressionParser return $expr; } - /** - * @return ArrowFunctionExpression|null - */ - private function parseArrow() + private function parseArrow(): ?ArrowFunctionExpression { $stream = $this->parser->getStream(); diff --git a/src/ExtensionSet.php b/src/ExtensionSet.php index 20c6ba448..b0c9e9f1b 100644 --- a/src/ExtensionSet.php +++ b/src/ExtensionSet.php @@ -34,7 +34,7 @@ final class ExtensionSet private array $extensions; private bool $initialized = false; private bool $runtimeInitialized = false; - private $staging; + private StagingExtension $staging; /** * @var TokenParserInterface[] diff --git a/src/Lexer.php b/src/Lexer.php index b4fde986c..0c00c4604 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -88,7 +88,7 @@ class Lexer ], $options); } - private function initialize() + private function initialize(): void { if ($this->isInitialized) { return; @@ -525,7 +525,7 @@ class Lexer } } - private function pushToken($type, $value = ''): void + private function pushToken(int $type, $value = ''): void { // do not push empty text tokens if (Token::TEXT_TYPE === $type && '' === $value) { @@ -535,7 +535,7 @@ class Lexer $this->tokens[] = new Token($type, $value, $this->lineno); } - private function moveCursor($text): void + private function moveCursor(string $text): void { $this->cursor += \strlen($text); $this->lineno += substr_count($text, "\n"); diff --git a/src/Loader/ChainLoader.php b/src/Loader/ChainLoader.php index 4c04dd8d4..1f0a6a393 100644 --- a/src/Loader/ChainLoader.php +++ b/src/Loader/ChainLoader.php @@ -29,7 +29,7 @@ final class ChainLoader implements LoaderInterface /** * @var array */ - private $hasSourceCache = []; + private array $hasSourceCache = []; /** * @param iterable $loaders diff --git a/src/Node/Expression/Test/DefinedTest.php b/src/Node/Expression/Test/DefinedTest.php index 10a26e0a7..d3ad881a0 100644 --- a/src/Node/Expression/Test/DefinedTest.php +++ b/src/Node/Expression/Test/DefinedTest.php @@ -60,7 +60,7 @@ class DefinedTest extends TestExpression parent::__construct($node, $name, $arguments, $lineno); } - private function changeIgnoreStrictCheck(GetAttrExpression $node) + private function changeIgnoreStrictCheck(GetAttrExpression $node): void { $node->setAttribute('optimizable', false); $node->setAttribute('ignore_strict_check', true); diff --git a/src/Node/NameDeprecation.php b/src/Node/NameDeprecation.php index 63ab28576..131c29369 100644 --- a/src/Node/NameDeprecation.php +++ b/src/Node/NameDeprecation.php @@ -18,9 +18,9 @@ namespace Twig\Node; */ class NameDeprecation { - private $package; - private $version; - private $newName; + private string $package; + private string $version; + private string $newName; public function __construct(string $package = '', string $version = '', string $newName = '') { diff --git a/src/Node/Node.php b/src/Node/Node.php index bcddd4a7d..0fea4ca54 100644 --- a/src/Node/Node.php +++ b/src/Node/Node.php @@ -32,9 +32,9 @@ class Node implements \Countable, \IteratorAggregate private ?Source $sourceContext = null; /** @var array */ - private $nodeNameDeprecations = []; + private array $nodeNameDeprecations = []; /** @var array */ - private $attributeNameDeprecations = []; + private array $attributeNameDeprecations = []; /** * @param array $nodes An array of named nodes diff --git a/src/NodeVisitor/EscaperNodeVisitor.php b/src/NodeVisitor/EscaperNodeVisitor.php index 93cff933d..8b28f798d 100644 --- a/src/NodeVisitor/EscaperNodeVisitor.php +++ b/src/NodeVisitor/EscaperNodeVisitor.php @@ -182,7 +182,7 @@ final class EscaperNodeVisitor implements NodeVisitorInterface return \in_array($type, $safe) || \in_array('all', $safe); } - private function needEscaping() + private function needEscaping(): string|false { if (\count($this->statusStack)) { return $this->statusStack[\count($this->statusStack) - 1]; diff --git a/src/NodeVisitor/SafeAnalysisNodeVisitor.php b/src/NodeVisitor/SafeAnalysisNodeVisitor.php index 902f765a1..8964ddb7e 100644 --- a/src/NodeVisitor/SafeAnalysisNodeVisitor.php +++ b/src/NodeVisitor/SafeAnalysisNodeVisitor.php @@ -28,8 +28,8 @@ use Twig\Node\Node; */ final class SafeAnalysisNodeVisitor implements NodeVisitorInterface { - private $data = []; - private $safeVars = []; + private array $data = []; + private array $safeVars = []; public function setSafeVars(array $safeVars): void { diff --git a/src/Profiler/Dumper/BlackfireDumper.php b/src/Profiler/Dumper/BlackfireDumper.php index bb3fbb52a..7cfae16f1 100644 --- a/src/Profiler/Dumper/BlackfireDumper.php +++ b/src/Profiler/Dumper/BlackfireDumper.php @@ -40,7 +40,7 @@ EOF; return $str; } - private function dumpChildren(string $parent, Profile $profile, &$data) + private function dumpChildren(string $parent, Profile $profile, &$data): void { foreach ($profile as $p) { if ($p->isTemplate()) { @@ -53,7 +53,7 @@ EOF; } } - private function dumpProfile(string $edge, Profile $profile, &$data) + private function dumpProfile(string $edge, Profile $profile, &$data): void { if (isset($data[$edge])) { ++$data[$edge]['ct']; diff --git a/src/Runtime/EscaperRuntime.php b/src/Runtime/EscaperRuntime.php index 64b82e6c7..664ef6092 100644 --- a/src/Runtime/EscaperRuntime.php +++ b/src/Runtime/EscaperRuntime.php @@ -18,7 +18,7 @@ use Twig\Markup; final class EscaperRuntime implements RuntimeExtensionInterface { /** @var array */ - private $escapers = []; + private array $escapers = []; /** @internal */ public array $safeClasses = []; @@ -316,7 +316,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface } } - private function convertEncoding(string $string, string $to, string $from) + private function convertEncoding(string $string, string $to, string $from): string { if (!\function_exists('iconv')) { throw new RuntimeError('Unable to convert encoding: required function iconv() does not exist. You should install ext-iconv or symfony/polyfill-iconv.'); diff --git a/src/Test/NodeTestCase.php b/src/Test/NodeTestCase.php index 799f0877a..14d4d47e3 100644 --- a/src/Test/NodeTestCase.php +++ b/src/Test/NodeTestCase.php @@ -19,10 +19,7 @@ use Twig\Node\Node; abstract class NodeTestCase extends TestCase { - /** - * @var Environment - */ - private $currentEnv; + private Environment $currentEnv; abstract public function getTests(); diff --git a/src/Token.php b/src/Token.php index 2f5228c37..fe1738a99 100644 --- a/src/Token.php +++ b/src/Token.php @@ -18,8 +18,8 @@ namespace Twig; final class Token { private $value; - private $type; - private $lineno; + private int $type; + private int $lineno; public const EOF_TYPE = -1; public const TEXT_TYPE = 0;