diff --git a/lib/PhpParser/Builder/Declaration.php b/lib/PhpParser/Builder/Declaration.php index df50cfb676..6d71657cb3 100644 --- a/lib/PhpParser/Builder/Declaration.php +++ b/lib/PhpParser/Builder/Declaration.php @@ -8,6 +8,13 @@ abstract class Declaration implements PhpParser\Builder { protected $attributes = []; + /** + * Adds a statement. + * + * @param PhpParser\Node\Stmt|PhpParser\Builder $stmt The statement to add + * + * @return $this The builder instance (for fluid interface) + */ abstract public function addStmt($stmt); /** diff --git a/lib/PhpParser/Internal/DiffElem.php b/lib/PhpParser/Internal/DiffElem.php index d10409f400..b25925d2d4 100644 --- a/lib/PhpParser/Internal/DiffElem.php +++ b/lib/PhpParser/Internal/DiffElem.php @@ -18,6 +18,11 @@ class DiffElem { /** @var mixed Is null for remove operations */ public $new; + /** + * @param int $type One of the TYPE_* constants + * @param mixed $old Is null for add operations + * @param mixed $new Is null for remove operations + */ public function __construct(int $type, $old, $new) { $this->type = $type; $this->old = $old; diff --git a/lib/PhpParser/Internal/TokenStream.php b/lib/PhpParser/Internal/TokenStream.php index 72a28dcae9..5dbd9912ad 100644 --- a/lib/PhpParser/Internal/TokenStream.php +++ b/lib/PhpParser/Internal/TokenStream.php @@ -102,6 +102,7 @@ public function haveTokenImmediatelyAfter(int $pos, $expectedTokenType): bool { return false; } + /** @param int|string|array $skipTokenType */ public function skipLeft(int $pos, $skipTokenType) { $tokens = $this->tokens; @@ -119,6 +120,7 @@ public function skipLeft(int $pos, $skipTokenType) { return $this->skipLeftWhitespace($pos); } + /** @param int|string|array $skipTokenType */ public function skipRight(int $pos, $skipTokenType) { $tokens = $this->tokens; @@ -168,6 +170,7 @@ public function skipRightWhitespace(int $pos): int { return $pos; } + /** @param int|string|array $findTokenType */ public function findRight(int $pos, $findTokenType) { $tokens = $this->tokens; for ($count = \count($tokens); $pos < $count; $pos++) { diff --git a/lib/PhpParser/JsonDecoder.php b/lib/PhpParser/JsonDecoder.php index fa9d661977..d4965c7be0 100644 --- a/lib/PhpParser/JsonDecoder.php +++ b/lib/PhpParser/JsonDecoder.php @@ -15,6 +15,7 @@ public function decode(string $json) { return $this->decodeRecursive($value); } + /** @param mixed $value */ private function decodeRecursive($value) { if (\is_array($value)) { if (isset($value['nodeType'])) { diff --git a/lib/PhpParser/NameContext.php b/lib/PhpParser/NameContext.php index 9aa50f438e..94afb4b8ad 100644 --- a/lib/PhpParser/NameContext.php +++ b/lib/PhpParser/NameContext.php @@ -226,7 +226,7 @@ public function getShortName(string $name, int $type): Name { return $shortestName; } - private function resolveAlias(Name $name, $type) { + private function resolveAlias(Name $name, int $type) { $firstPart = $name->getFirst(); if ($name->isQualified()) { diff --git a/lib/PhpParser/Node/Stmt/Class_.php b/lib/PhpParser/Node/Stmt/Class_.php index 453cffe472..04ae6a1fea 100644 --- a/lib/PhpParser/Node/Stmt/Class_.php +++ b/lib/PhpParser/Node/Stmt/Class_.php @@ -92,7 +92,7 @@ public function isAnonymous(): bool { /** * @internal */ - public static function verifyClassModifier($a, $b) { + public static function verifyClassModifier(int $a, int $b) { if ($a & Modifiers::ABSTRACT && $b & Modifiers::ABSTRACT) { throw new Error('Multiple abstract modifiers are not allowed'); } @@ -113,7 +113,7 @@ public static function verifyClassModifier($a, $b) { /** * @internal */ - public static function verifyModifier($a, $b) { + public static function verifyModifier(int $a, int $b) { if ($a & Modifiers::VISIBILITY_MASK && $b & Modifiers::VISIBILITY_MASK) { throw new Error('Multiple access type modifiers are not allowed'); } diff --git a/lib/PhpParser/NodeDumper.php b/lib/PhpParser/NodeDumper.php index 802f483986..78f8d76e94 100644 --- a/lib/PhpParser/NodeDumper.php +++ b/lib/PhpParser/NodeDumper.php @@ -43,6 +43,7 @@ public function dump($node, ?string $code = null): string { return $this->dumpRecursive($node); } + /** @param Node|Comment|array $node */ protected function dumpRecursive($node) { if ($node instanceof Node) { $r = $node->getType(); @@ -107,7 +108,7 @@ protected function dumpRecursive($node) { return $r . "\n)"; } - protected function dumpFlags($flags) { + protected function dumpFlags(int $flags) { $strs = []; if ($flags & Modifiers::PUBLIC) { $strs[] = 'PUBLIC'; @@ -138,7 +139,7 @@ protected function dumpFlags($flags) { } } - protected function dumpIncludeType($type) { + protected function dumpIncludeType(int $type) { $map = [ Include_::TYPE_INCLUDE => 'TYPE_INCLUDE', Include_::TYPE_INCLUDE_ONCE => 'TYPE_INCLUDE_ONCE', @@ -152,7 +153,7 @@ protected function dumpIncludeType($type) { return $map[$type] . ' (' . $type . ')'; } - protected function dumpUseType($type) { + protected function dumpUseType(int $type) { $map = [ Use_::TYPE_UNKNOWN => 'TYPE_UNKNOWN', Use_::TYPE_NORMAL => 'TYPE_NORMAL', @@ -190,7 +191,7 @@ protected function dumpPosition(Node $node): ?string { } // Copied from Error class - private function toColumn($code, $pos) { + private function toColumn(string $code, int $pos) { if ($pos > strlen($code)) { throw new \RuntimeException('Invalid position information'); } diff --git a/lib/PhpParser/NodeTraverser.php b/lib/PhpParser/NodeTraverser.php index 0d81aedb37..427e59993a 100644 --- a/lib/PhpParser/NodeTraverser.php +++ b/lib/PhpParser/NodeTraverser.php @@ -272,7 +272,7 @@ protected function traverseArray(array $nodes): array { return $nodes; } - private function ensureReplacementReasonable($old, $new) { + private function ensureReplacementReasonable(Node $old, Node $new) { if ($old instanceof Node\Stmt && $new instanceof Node\Expr) { throw new \LogicException( "Trying to replace statement ({$old->getType()}) " . diff --git a/lib/PhpParser/NodeVisitor/NameResolver.php b/lib/PhpParser/NodeVisitor/NameResolver.php index d00374bf43..e0352a0082 100644 --- a/lib/PhpParser/NodeVisitor/NameResolver.php +++ b/lib/PhpParser/NodeVisitor/NameResolver.php @@ -160,7 +160,7 @@ public function enterNode(Node $node) { return null; } - private function addAlias(Node\UseItem $use, $type, ?Name $prefix = null) { + private function addAlias(Node\UseItem $use, int $type, ?Name $prefix = null) { // Add prefix for group uses $name = $prefix ? Name::concat($prefix, $use->name) : $use->name; // Type is determined either by individual element or whole use declaration @@ -180,7 +180,7 @@ private function resolveSignature($node) { $node->returnType = $this->resolveType($node->returnType); } - private function resolveType($node) { + private function resolveType(?Node $node) { if ($node instanceof Name) { return $this->resolveClassName($node); } diff --git a/lib/PhpParser/ParserAbstract.php b/lib/PhpParser/ParserAbstract.php index dccc5865f6..3686206759 100644 --- a/lib/PhpParser/ParserAbstract.php +++ b/lib/PhpParser/ParserAbstract.php @@ -11,6 +11,7 @@ use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Cast\Double; +use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\Param; use PhpParser\Node\Scalar\InterpolatedString; @@ -662,7 +663,7 @@ protected function getFloatCastKind(string $cast): int { return Double::KIND_DOUBLE; } - protected function parseLNumber($str, $attributes, $allowInvalidOctal = false) { + protected function parseLNumber(string $str, array $attributes, bool $allowInvalidOctal = false) { try { return Int_::fromString($str, $attributes, $allowInvalidOctal); } catch (Error $error) { @@ -725,6 +726,7 @@ function ($matches) use ($indentLen, $indentChar, $attributes) { ); } + /** @param string|array $contents */ protected function parseDocString( string $startToken, $contents, string $endToken, array $attributes, array $endTokenAttributes, bool $parseUnicodeEscape @@ -872,7 +874,7 @@ protected function postprocessList(Expr\List_ $node): void { } } - protected function checkClassModifier($a, $b, $modifierPos) { + protected function checkClassModifier(int $a, int $b, int $modifierPos) { try { Class_::verifyClassModifier($a, $b); } catch (Error $error) { @@ -881,7 +883,7 @@ protected function checkClassModifier($a, $b, $modifierPos) { } } - protected function checkModifier($a, $b, $modifierPos) { + protected function checkModifier(int $a, int $b, int $modifierPos) { // Jumping through some hoops here because verifyModifier() is also used elsewhere try { Class_::verifyModifier($a, $b); @@ -920,7 +922,7 @@ protected function checkNamespace(Namespace_ $node) { } } - private function checkClassName($name, $namePos) { + private function checkClassName(?Identifier $name, int $namePos) { if (null !== $name && $name->isSpecialClassName()) { $this->emitError(new Error( sprintf('Cannot use \'%s\' as class name as it is reserved', $name), @@ -940,7 +942,7 @@ private function checkImplementedInterfaces(array $interfaces) { } } - protected function checkClass(Class_ $node, $namePos) { + protected function checkClass(Class_ $node, int $namePos) { $this->checkClassName($node->name, $namePos); if ($node->extends && $node->extends->isSpecialClassName()) { @@ -953,17 +955,17 @@ protected function checkClass(Class_ $node, $namePos) { $this->checkImplementedInterfaces($node->implements); } - protected function checkInterface(Interface_ $node, $namePos) { + protected function checkInterface(Interface_ $node, int $namePos) { $this->checkClassName($node->name, $namePos); $this->checkImplementedInterfaces($node->extends); } - protected function checkEnum(Enum_ $node, $namePos) { + protected function checkEnum(Enum_ $node, int $namePos) { $this->checkClassName($node->name, $namePos); $this->checkImplementedInterfaces($node->implements); } - protected function checkClassMethod(ClassMethod $node, $modifierPos) { + protected function checkClassMethod(ClassMethod $node, int $modifierPos) { if ($node->flags & Modifiers::STATIC) { switch ($node->name->toLowerString()) { case '__construct': @@ -991,7 +993,7 @@ protected function checkClassMethod(ClassMethod $node, $modifierPos) { } } - protected function checkClassConst(ClassConst $node, $modifierPos) { + protected function checkClassConst(ClassConst $node, int $modifierPos) { if ($node->flags & Modifiers::STATIC) { $this->emitError(new Error( "Cannot use 'static' as constant modifier", @@ -1009,7 +1011,7 @@ protected function checkClassConst(ClassConst $node, $modifierPos) { } } - protected function checkProperty(Property $node, $modifierPos) { + protected function checkProperty(Property $node, int $modifierPos) { if ($node->flags & Modifiers::ABSTRACT) { $this->emitError(new Error('Properties cannot be declared abstract', $this->getAttributesAt($modifierPos))); @@ -1021,7 +1023,7 @@ protected function checkProperty(Property $node, $modifierPos) { } } - protected function checkUseUse(UseItem $node, $namePos) { + protected function checkUseUse(UseItem $node, int $namePos) { if ($node->alias && $node->alias->isSpecialClassName()) { $this->emitError(new Error( sprintf( diff --git a/lib/PhpParser/PrettyPrinter/Standard.php b/lib/PhpParser/PrettyPrinter/Standard.php index be4ddcf113..6241aec6a9 100644 --- a/lib/PhpParser/PrettyPrinter/Standard.php +++ b/lib/PhpParser/PrettyPrinter/Standard.php @@ -736,7 +736,7 @@ protected function pUseItem(Node\UseItem $node) { . (null !== $node->alias ? ' as ' . $node->alias : ''); } - protected function pUseType($type) { + protected function pUseType(int $type) { return $type === Stmt\Use_::TYPE_FUNCTION ? 'function ' : ($type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : ''); } @@ -978,7 +978,7 @@ protected function pStmt_Nop(Stmt\Nop $node) { // Helpers - protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) { + protected function pClassCommon(Stmt\Class_ $node, string $afterClassToken) { return $this->pAttrGroups($node->attrGroups, $node->name === null) . $this->pModifiers($node->flags) . 'class' . $afterClassToken @@ -987,7 +987,7 @@ protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) { . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; } - protected function pObjectProperty($node) { + protected function pObjectProperty(Node $node) { if ($node instanceof Expr) { return '{' . $this->p($node) . '}'; } else { @@ -995,7 +995,7 @@ protected function pObjectProperty($node) { } } - protected function pEncapsList(array $encapsList, $quote) { + protected function pEncapsList(array $encapsList, ?string $quote) { $return = ''; foreach ($encapsList as $element) { if ($element instanceof Node\InterpolatedStringPart) { @@ -1017,7 +1017,7 @@ protected function pSingleQuotedString(string $string) { return '\'' . preg_replace($regex, '\\\\$0', $string) . '\''; } - protected function escapeString($string, $quote) { + protected function escapeString(string $string, ?string $quote) { if (null === $quote) { // For doc strings, don't escape newlines $escaped = addcslashes($string, "\t\f\v$\\"); @@ -1050,14 +1050,14 @@ protected function escapeString($string, $quote) { }, $escaped); } - protected function containsEndLabel($string, $label, $atStart = true, $atEnd = true) { + protected function containsEndLabel(string $string, string $label, bool $atStart = true, bool $atEnd = true) { $start = $atStart ? '(?:^|[\r\n])' : '[\r\n]'; $end = $atEnd ? '(?:$|[;\r\n])' : '[;\r\n]'; return false !== strpos($string, $label) && preg_match('/' . $start . $label . $end . '/', $string); } - protected function encapsedContainsEndLabel(array $parts, $label) { + protected function encapsedContainsEndLabel(array $parts, string $label) { foreach ($parts as $i => $part) { $atStart = $i === 0; $atEnd = $i === count($parts) - 1;