diff --git a/lib/PhpParser/Lexer.php b/lib/PhpParser/Lexer.php index f00015071a..1298702b67 100644 --- a/lib/PhpParser/Lexer.php +++ b/lib/PhpParser/Lexer.php @@ -2,8 +2,6 @@ namespace PhpParser; -use PhpParser\Parser\Tokens; - require __DIR__ . '/compatibility_tokens.php'; class Lexer { @@ -36,11 +34,11 @@ class Lexer { /** * Creates a Lexer. * - * @param array $options Options array. Currently only the 'usedAttributes' option is supported, - * which is an array of attributes to add to the AST nodes. Possible - * attributes are: 'comments', 'startLine', 'endLine', 'startTokenPos', - * 'endTokenPos', 'startFilePos', 'endFilePos'. The option defaults to the - * first three. For more info see getNextToken() docs. + * @param array{usedAttributes?: string[]} $options Options array. Currently only the + * 'usedAttributes' option is supported, which is an array of attributes to add to the + * AST nodes. Possible attributes are: 'comments', 'startLine', 'endLine', 'startTokenPos', + * 'endTokenPos', 'startFilePos', 'endFilePos'. The option defaults to the first three. + * For more info see getNextToken() docs. */ public function __construct(array $options = []) { // map of tokens to drop while lexing (the map is only used for isset lookup, diff --git a/lib/PhpParser/Lexer/Emulative.php b/lib/PhpParser/Lexer/Emulative.php index 41afa7edfe..c382f8f366 100644 --- a/lib/PhpParser/Lexer/Emulative.php +++ b/lib/PhpParser/Lexer/Emulative.php @@ -20,7 +20,7 @@ use PhpParser\PhpVersion; class Emulative extends Lexer { - /** @var mixed[] Patches used to reverse changes introduced in the code */ + /** @var array{int, string, string}[] Patches used to reverse changes introduced in the code */ private $patches = []; /** @var TokenEmulator[] */ @@ -32,9 +32,9 @@ class Emulative extends Lexer { private $hostPhpVersion; /** - * @param mixed[] $options Lexer options. In addition to the usual options, accepts a - * 'phpVersion' (PhpVersion object or string) that specifies the - * version to emulate. Defaults to newest supported. + * @param array{usedAttributes?: string[], phpVersion?: PhpVersion|string} $options Lexer options. + * In addition to the usual options, accepts a 'phpVersion' (PhpVersion object or string) + * that specifies the version to emulate. Defaults to newest supported. */ public function __construct(array $options = []) { $version = $options['phpVersion'] ?? PhpVersion::getNewestSupported(); diff --git a/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php b/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php index 53f65b14d5..fec2f19f44 100644 --- a/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php +++ b/lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php @@ -18,10 +18,12 @@ abstract public function isEmulationNeeded(string $code): bool; abstract public function emulate(string $code, array $tokens): array; /** + * @param Token[] $tokens Original tokens * @return Token[] Modified Tokens */ abstract public function reverseEmulate(string $code, array $tokens): array; + /** @param array{int, string, string}[] $patches */ public function preprocessCode(string $code, array &$patches): string { return $code; } diff --git a/lib/PhpParser/NameContext.php b/lib/PhpParser/NameContext.php index 946be0ee0b..5c7f12f8e8 100644 --- a/lib/PhpParser/NameContext.php +++ b/lib/PhpParser/NameContext.php @@ -50,7 +50,7 @@ public function startNamespace(?Name $namespace = null): void { * @param Name $name Original name * @param string $aliasName Aliased name * @param int $type One of Stmt\Use_::TYPE_* - * @param array $errorAttrs Attributes to use to report an error + * @param array $errorAttrs Attributes to use to report an error */ public function addAlias(Name $name, string $aliasName, int $type, array $errorAttrs = []): void { // Constant names are case sensitive, everything else case insensitive diff --git a/lib/PhpParser/Node/Expr/ArrowFunction.php b/lib/PhpParser/Node/Expr/ArrowFunction.php index 4a9e5ed186..98e24a5104 100644 --- a/lib/PhpParser/Node/Expr/ArrowFunction.php +++ b/lib/PhpParser/Node/Expr/ArrowFunction.php @@ -25,16 +25,23 @@ class ArrowFunction extends Expr implements FunctionLike { public $attrGroups; /** - * @param array $subNodes Array of the following optional subnodes: - * 'static' => false : Whether the closure is static - * 'byRef' => false : Whether to return by reference - * 'params' => array() : Parameters - * 'returnType' => null : Return type - * 'expr' => Expr : Expression body - * 'attrGroups' => array() : PHP attribute groups + * @param array{ + * expr: Expr, + * static?: bool, + * byRef?: bool, + * params?: Node\Param[], + * returnType?: null|string|Node\Identifier|Node\Name|Node\ComplexType, + * attrGroups?: Node\AttributeGroup[] + * } $subNodes Array of the following subnodes: + * 'expr' : Expression body + * 'static' => false : Whether the closure is static + * 'byRef' => false : Whether to return by reference + * 'params' => array() : Parameters + * 'returnType' => null : Return type + * 'attrGroups' => array() : PHP attribute groups * @param array $attributes Additional attributes */ - public function __construct(array $subNodes = [], array $attributes = []) { + public function __construct(array $subNodes, array $attributes = []) { $this->attributes = $attributes; $this->static = $subNodes['static'] ?? false; $this->byRef = $subNodes['byRef'] ?? false; diff --git a/lib/PhpParser/Node/Expr/Closure.php b/lib/PhpParser/Node/Expr/Closure.php index caa566c536..ee257d49db 100644 --- a/lib/PhpParser/Node/Expr/Closure.php +++ b/lib/PhpParser/Node/Expr/Closure.php @@ -26,14 +26,22 @@ class Closure extends Expr implements FunctionLike { /** * Constructs a lambda function node. * - * @param array $subNodes Array of the following optional subnodes: - * 'static' => false : Whether the closure is static - * 'byRef' => false : Whether to return by reference - * 'params' => array(): Parameters - * 'uses' => array(): use()s - * 'returnType' => null : Return type - * 'stmts' => array(): Statements - * 'attrGroups' => array(): PHP attributes groups + * @param array{ + * static?: bool, + * byRef?: bool, + * params?: Node\Param[], + * uses?: ClosureUse[], + * returnType?: null|string|Node\Identifier|Node\Name|Node\ComplexType, + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'static' => false : Whether the closure is static + * 'byRef' => false : Whether to return by reference + * 'params' => array(): Parameters + * 'uses' => array(): use()s + * 'returnType' => null : Return type + * 'stmts' => array(): Statements + * 'attrGroups' => array(): PHP attributes groups * @param array $attributes Additional attributes */ public function __construct(array $subNodes = [], array $attributes = []) { diff --git a/lib/PhpParser/Node/Expr/ShellExec.php b/lib/PhpParser/Node/Expr/ShellExec.php index 68907ab66c..5fe85d7168 100644 --- a/lib/PhpParser/Node/Expr/ShellExec.php +++ b/lib/PhpParser/Node/Expr/ShellExec.php @@ -3,15 +3,16 @@ namespace PhpParser\Node\Expr; use PhpParser\Node\Expr; +use PhpParser\Node\InterpolatedStringPart; class ShellExec extends Expr { - /** @var array Encapsed string array */ + /** @var (Expr|InterpolatedStringPart)[] Interpolated string array */ public $parts; /** * Constructs a shell exec (backtick) node. * - * @param array $parts Encapsed string array + * @param (Expr|InterpolatedStringPart)[] $parts Interpolated string array * @param array $attributes Additional attributes */ public function __construct(array $parts, array $attributes = []) { diff --git a/lib/PhpParser/Node/Identifier.php b/lib/PhpParser/Node/Identifier.php index 01f3e28985..000499957a 100644 --- a/lib/PhpParser/Node/Identifier.php +++ b/lib/PhpParser/Node/Identifier.php @@ -11,6 +11,7 @@ class Identifier extends NodeAbstract { /** @var string Identifier as string */ public $name; + /** @var array */ private static $specialClassNames = [ 'self' => true, 'parent' => true, diff --git a/lib/PhpParser/Node/Name.php b/lib/PhpParser/Node/Name.php index 4e6ae0a9fe..07bcbfd67b 100644 --- a/lib/PhpParser/Node/Name.php +++ b/lib/PhpParser/Node/Name.php @@ -8,6 +8,7 @@ class Name extends NodeAbstract { /** @var string[] Parts of the name */ public $parts; + /** @var array */ private static $specialClassNames = [ 'self' => true, 'parent' => true, diff --git a/lib/PhpParser/Node/Scalar/String_.php b/lib/PhpParser/Node/Scalar/String_.php index 91f4c78e6c..f836fcb3e5 100644 --- a/lib/PhpParser/Node/Scalar/String_.php +++ b/lib/PhpParser/Node/Scalar/String_.php @@ -15,6 +15,7 @@ class String_ extends Scalar { /** @var string String value */ public $value; + /** @var array Escaped character to its decoded value */ protected static $replacements = [ '\\' => '\\', '$' => '$', @@ -42,6 +43,7 @@ public function getSubNodeNames(): array { } /** + * @param array $attributes * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes */ public static function fromString(string $str, array $attributes = [], bool $parseUnicodeEscape = true): self { diff --git a/lib/PhpParser/Node/Stmt/ClassMethod.php b/lib/PhpParser/Node/Stmt/ClassMethod.php index 4e5e3f0593..927e6f3408 100644 --- a/lib/PhpParser/Node/Stmt/ClassMethod.php +++ b/lib/PhpParser/Node/Stmt/ClassMethod.php @@ -22,6 +22,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike { /** @var Node\AttributeGroup[] PHP attribute groups */ public $attrGroups; + /** @var array */ private static $magicNames = [ '__construct' => true, '__destruct' => true, @@ -46,13 +47,20 @@ class ClassMethod extends Node\Stmt implements FunctionLike { * Constructs a class method node. * * @param string|Node\Identifier $name Name - * @param array $subNodes Array of the following optional subnodes: - * 'flags => 0 : Flags - * 'byRef' => false : Whether to return by reference - * 'params' => array() : Parameters - * 'returnType' => null : Return type - * 'stmts' => array() : Statements - * 'attrGroups' => array() : PHP attribute groups + * @param array{ + * flags?: int, + * byRef?: bool, + * params?: Node\Param[], + * returnType?: null|string|Node\Identifier|Node\Name|Node\ComplexType, + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'flags => 0 : Flags + * 'byRef' => false : Whether to return by reference + * 'params' => array() : Parameters + * 'returnType' => null : Return type + * 'stmts' => array() : Statements + * 'attrGroups' => array() : PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { diff --git a/lib/PhpParser/Node/Stmt/Class_.php b/lib/PhpParser/Node/Stmt/Class_.php index 428d2a9059..98bf9fd7c0 100644 --- a/lib/PhpParser/Node/Stmt/Class_.php +++ b/lib/PhpParser/Node/Stmt/Class_.php @@ -36,12 +36,18 @@ class Class_ extends ClassLike { * Constructs a class node. * * @param string|Node\Identifier|null $name Name - * @param array $subNodes Array of the following optional subnodes: - * 'flags' => 0 : Flags - * 'extends' => null : Name of extended class - * 'implements' => array(): Names of implemented interfaces - * 'stmts' => array(): Statements - * 'attrGroups' => array(): PHP attribute groups + * @param array{ + * flags?: int, + * extends?: Node\Name|null, + * implements?: Node\Name[], + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'flags' => 0 : Flags + * 'extends' => null : Name of extended class + * 'implements' => array(): Names of implemented interfaces + * 'stmts' => array(): Statements + * 'attrGroups' => array(): PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { diff --git a/lib/PhpParser/Node/Stmt/Enum_.php b/lib/PhpParser/Node/Stmt/Enum_.php index 62b4aa079b..429cda0273 100644 --- a/lib/PhpParser/Node/Stmt/Enum_.php +++ b/lib/PhpParser/Node/Stmt/Enum_.php @@ -11,12 +11,17 @@ class Enum_ extends ClassLike { public $implements; /** - * @param string|Node\Identifier|null $name Name - * @param array $subNodes Array of the following optional subnodes: - * 'scalarType' => null : Scalar type - * 'implements' => array() : Names of implemented interfaces - * 'stmts' => array() : Statements - * 'attrGroups' => array() : PHP attribute groups + * @param string|Node\Identifier|null $name Name + * @param array{ + * scalarType?: Node\Identifier|null, + * implements?: Node\Name[], + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'scalarType' => null : Scalar type + * 'implements' => array() : Names of implemented interfaces + * 'stmts' => array() : Statements + * 'attrGroups' => array() : PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { diff --git a/lib/PhpParser/Node/Stmt/For_.php b/lib/PhpParser/Node/Stmt/For_.php index 3592c142b7..00dbd14743 100644 --- a/lib/PhpParser/Node/Stmt/For_.php +++ b/lib/PhpParser/Node/Stmt/For_.php @@ -17,11 +17,16 @@ class For_ extends Node\Stmt { /** * Constructs a for loop node. * - * @param array $subNodes Array of the following optional subnodes: - * 'init' => array(): Init expressions - * 'cond' => array(): Loop conditions - * 'loop' => array(): Loop expressions - * 'stmts' => array(): Statements + * @param array{ + * init?: Node\Expr[], + * cond?: Node\Expr[], + * loop?: Node\Expr[], + * stmts?: Node\Stmt[], + * } $subNodes Array of the following optional subnodes: + * 'init' => array(): Init expressions + * 'cond' => array(): Loop conditions + * 'loop' => array(): Loop expressions + * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct(array $subNodes = [], array $attributes = []) { diff --git a/lib/PhpParser/Node/Stmt/Foreach_.php b/lib/PhpParser/Node/Stmt/Foreach_.php index b341d85a19..c347d4e125 100644 --- a/lib/PhpParser/Node/Stmt/Foreach_.php +++ b/lib/PhpParser/Node/Stmt/Foreach_.php @@ -21,10 +21,14 @@ class Foreach_ extends Node\Stmt { * * @param Node\Expr $expr Expression to iterate * @param Node\Expr $valueVar Variable to assign value to - * @param array $subNodes Array of the following optional subnodes: - * 'keyVar' => null : Variable to assign key to - * 'byRef' => false : Whether to assign value by reference - * 'stmts' => array(): Statements + * @param array{ + * keyVar?: Node\Expr|null, + * byRef?: bool, + * stmts?: Node\Stmt[], + * } $subNodes Array of the following optional subnodes: + * 'keyVar' => null : Variable to assign key to + * 'byRef' => false : Whether to assign value by reference + * 'stmts' => array(): Statements * @param array $attributes Additional attributes */ public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNodes = [], array $attributes = []) { diff --git a/lib/PhpParser/Node/Stmt/Function_.php b/lib/PhpParser/Node/Stmt/Function_.php index aa8372b216..8948e21112 100644 --- a/lib/PhpParser/Node/Stmt/Function_.php +++ b/lib/PhpParser/Node/Stmt/Function_.php @@ -26,12 +26,18 @@ class Function_ extends Node\Stmt implements FunctionLike { * Constructs a function node. * * @param string|Node\Identifier $name Name - * @param array $subNodes Array of the following optional subnodes: - * 'byRef' => false : Whether to return by reference - * 'params' => array(): Parameters - * 'returnType' => null : Return type - * 'stmts' => array(): Statements - * 'attrGroups' => array(): PHP attribute groups + * @param array{ + * byRef?: bool, + * params?: Node\Param[], + * returnType?: null|string|Node\Identifier|Node\Name|Node\ComplexType, + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'byRef' => false : Whether to return by reference + * 'params' => array(): Parameters + * 'returnType' => null : Return type + * 'stmts' => array(): Statements + * 'attrGroups' => array(): PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { diff --git a/lib/PhpParser/Node/Stmt/If_.php b/lib/PhpParser/Node/Stmt/If_.php index 57a9bb6dec..7c9289e7eb 100644 --- a/lib/PhpParser/Node/Stmt/If_.php +++ b/lib/PhpParser/Node/Stmt/If_.php @@ -17,11 +17,15 @@ class If_ extends Node\Stmt { /** * Constructs an if node. * - * @param Node\Expr $cond Condition - * @param array $subNodes Array of the following optional subnodes: - * 'stmts' => array(): Statements - * 'elseifs' => array(): Elseif clauses - * 'else' => null : Else clause + * @param Node\Expr $cond Condition + * @param array{ + * stmts?: Node\Stmt[], + * elseifs?: ElseIf_[], + * else?: Else_|null, + * } $subNodes Array of the following optional subnodes: + * 'stmts' => array(): Statements + * 'elseifs' => array(): Elseif clauses + * 'else' => null : Else clause * @param array $attributes Additional attributes */ public function __construct(Node\Expr $cond, array $subNodes = [], array $attributes = []) { diff --git a/lib/PhpParser/Node/Stmt/Interface_.php b/lib/PhpParser/Node/Stmt/Interface_.php index 8c8b4ee01f..fa0ef46501 100644 --- a/lib/PhpParser/Node/Stmt/Interface_.php +++ b/lib/PhpParser/Node/Stmt/Interface_.php @@ -12,10 +12,14 @@ class Interface_ extends ClassLike { * Constructs a class node. * * @param string|Node\Identifier $name Name - * @param array $subNodes Array of the following optional subnodes: - * 'extends' => array(): Name of extended interfaces - * 'stmts' => array(): Statements - * 'attrGroups' => array(): PHP attribute groups + * @param array{ + * extends?: Node\Name[], + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'extends' => array(): Name of extended interfaces + * 'stmts' => array(): Statements + * 'attrGroups' => array(): PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { diff --git a/lib/PhpParser/Node/Stmt/Trait_.php b/lib/PhpParser/Node/Stmt/Trait_.php index 694924e471..5f2b33070a 100644 --- a/lib/PhpParser/Node/Stmt/Trait_.php +++ b/lib/PhpParser/Node/Stmt/Trait_.php @@ -9,9 +9,12 @@ class Trait_ extends ClassLike { * Constructs a trait node. * * @param string|Node\Identifier $name Name - * @param array $subNodes Array of the following optional subnodes: - * 'stmts' => array(): Statements - * 'attrGroups' => array(): PHP attribute groups + * @param array{ + * stmts?: Node\Stmt[], + * attrGroups?: Node\AttributeGroup[], + * } $subNodes Array of the following optional subnodes: + * 'stmts' => array(): Statements + * 'attrGroups' => array(): PHP attribute groups * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = [], array $attributes = []) { diff --git a/lib/PhpParser/NodeAbstract.php b/lib/PhpParser/NodeAbstract.php index 3c8c2ecd3f..1d3bf26b2b 100644 --- a/lib/PhpParser/NodeAbstract.php +++ b/lib/PhpParser/NodeAbstract.php @@ -3,6 +3,7 @@ namespace PhpParser; abstract class NodeAbstract implements Node, \JsonSerializable { + /** @var array Attributes */ protected $attributes; /** @@ -169,7 +170,7 @@ public function setAttributes(array $attributes): void { } /** - * @return array + * @return array */ public function jsonSerialize(): array { return ['nodeType' => $this->getType()] + get_object_vars($this); diff --git a/lib/PhpParser/NodeDumper.php b/lib/PhpParser/NodeDumper.php index f48bc006f3..753f767c7a 100644 --- a/lib/PhpParser/NodeDumper.php +++ b/lib/PhpParser/NodeDumper.php @@ -9,8 +9,11 @@ use PhpParser\Node\UseItem; class NodeDumper { + /** @var bool */ private $dumpComments; + /** @var bool */ private $dumpPositions; + /** @var string|null */ private $code; /** diff --git a/lib/PhpParser/NodeVisitor/NameResolver.php b/lib/PhpParser/NodeVisitor/NameResolver.php index b1214fcb3d..a6c1fd663d 100644 --- a/lib/PhpParser/NodeVisitor/NameResolver.php +++ b/lib/PhpParser/NodeVisitor/NameResolver.php @@ -32,7 +32,7 @@ class NameResolver extends NodeVisitorAbstract { * namespacedName attribute, as usual.) * * @param ErrorHandler|null $errorHandler Error handler - * @param array $options Options + * @param array{preserveOriginalNames?: bool, replaceNodes?: bool} $options Options */ public function __construct(?ErrorHandler $errorHandler = null, array $options = []) { $this->nameContext = new NameContext($errorHandler ?? new ErrorHandler\Throwing()); diff --git a/lib/PhpParser/ParserAbstract.php b/lib/PhpParser/ParserAbstract.php index bc4c432cc5..8767e33397 100644 --- a/lib/PhpParser/ParserAbstract.php +++ b/lib/PhpParser/ParserAbstract.php @@ -7,16 +7,17 @@ * turn is based on work by Masato Bito. */ -use PhpParser\Modifiers; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Cast\Double; use PhpParser\Node\Identifier; +use PhpParser\Node\InterpolatedStringPart; use PhpParser\Node\Name; use PhpParser\Node\Param; use PhpParser\Node\Scalar\InterpolatedString; use PhpParser\Node\Scalar\Int_; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassConst; use PhpParser\Node\Stmt\ClassMethod; @@ -58,6 +59,7 @@ abstract class ParserAbstract implements Parser { /** @var int Rule number signifying that an unexpected token was encountered */ protected $unexpectedTokenRule; + /** @var int */ protected $YY2TBLSTATE; /** @var int Number of non-leaf states */ protected $numNonLeafStates; @@ -68,7 +70,7 @@ abstract class ParserAbstract implements Parser { protected $tokenToSymbol; /** @var string[] Map of symbols to their names */ protected $symbolToName; - /** @var array Names of the production rules (only necessary for debugging) */ + /** @var array Names of the production rules (only necessary for debugging) */ protected $productions; /** @var int[] Map of states to a displacement into the $action table. The corresponding action for this @@ -109,15 +111,15 @@ abstract class ParserAbstract implements Parser { /** @var mixed Temporary value containing the result of last semantic action (reduction) */ protected $semValue; - /** @var array Semantic value stack (contains values of tokens and semantic action results) */ + /** @var mixed[] Semantic value stack (contains values of tokens and semantic action results) */ protected $semStack; - /** @var array[] Start attribute stack */ + /** @var array[] Start attribute stack */ protected $startAttributeStack; - /** @var array[] End attribute stack */ + /** @var array[] End attribute stack */ protected $endAttributeStack; - /** @var array End attributes of last *shifted* token */ + /** @var array End attributes of last *shifted* token */ protected $endAttributes; - /** @var array Start attributes of last *read* token */ + /** @var array Start attributes of last *read* token */ protected $lookaheadStartAttributes; /** @var ErrorHandler Error handler */ @@ -125,7 +127,7 @@ abstract class ParserAbstract implements Parser { /** @var int Error state, used to avoid error floods */ protected $errorState; - /** @var \SplObjectStorage|null Array nodes created during parsing, for postprocessing of empty elements. */ + /** @var \SplObjectStorage|null Array nodes created during parsing, for postprocessing of empty elements. */ protected $createdArrays; /** @@ -201,6 +203,7 @@ public function getLexer(): Lexer { return $this->lexer; } + /** @return Stmt[]|null */ protected function doParse(): ?array { // We start off with no lookahead-token $symbol = self::SYMBOL_NONE; @@ -579,6 +582,7 @@ private function fixupNamespaceAttributes(Node\Stmt\Namespace_ $stmt): void { } } + /** @return array */ private function getNamespaceErrorAttributes(Namespace_ $node): array { $attrs = $node->getAttributes(); // Adjust end attributes to only cover the "namespace" keyword, not the whole namespace. @@ -663,7 +667,7 @@ protected function handleBuiltinTypes(Name $name) { * * @param int $pos Stack location * - * @return array Combined start and end attributes + * @return array Combined start and end attributes */ protected function getAttributesAt(int $pos): array { return $this->startAttributeStack[$pos] + $this->endAttributeStack[$pos]; @@ -682,6 +686,7 @@ protected function getFloatCastKind(string $cast): int { return Double::KIND_DOUBLE; } + /** @param array $attributes */ protected function parseLNumber(string $str, array $attributes, bool $allowInvalidOctal = false): Int_ { try { return Int_::fromString($str, $attributes, $allowInvalidOctal); @@ -695,7 +700,7 @@ protected function parseLNumber(string $str, array $attributes, bool $allowInval /** * Parse a T_NUM_STRING token into either an integer or string node. * - * @param string $str Number string + * @param string $str Number string * @param array $attributes Attributes * * @return Int_|String_ Integer or string node. @@ -713,6 +718,7 @@ protected function parseNumString(string $str, array $attributes) { return new Int_($num, $attributes); } + /** @param array $attributes */ protected function stripIndentation( string $string, int $indentLen, string $indentChar, bool $newlineAtStart, bool $newlineAtEnd, array $attributes @@ -745,7 +751,11 @@ function ($matches) use ($indentLen, $indentChar, $attributes) { ); } - /** @param string|array $contents */ + /** + * @param string|(Expr|InterpolatedStringPart)[] $contents + * @param array $attributes + * @param array $endTokenAttributes + */ protected function parseDocString( string $startToken, $contents, string $endToken, array $attributes, array $endTokenAttributes, bool $parseUnicodeEscape @@ -831,7 +841,7 @@ protected function parseDocString( * Create attributes for a zero-length common-capturing nop. * * @param Comment[] $comments - * @return array + * @return array */ protected function createCommentNopAttributes(array $comments): array { $comment = $comments[count($comments) - 1]; @@ -855,6 +865,10 @@ protected function createCommentNopAttributes(array $comments): array { return $attributes; } + /** + * @param array $attrs + * @return array + */ protected function createEmptyElemAttributes(array $attrs): array { if (isset($attrs['startLine'])) { $attrs['endLine'] = $attrs['startLine']; @@ -968,6 +982,7 @@ private function checkClassName(?Identifier $name, int $namePos): void { } } + /** @param Name[] $interfaces */ private function checkImplementedInterfaces(array $interfaces): void { foreach ($interfaces as $interface) { if ($interface->isSpecialClassName()) { @@ -1079,7 +1094,7 @@ protected function checkUseUse(UseItem $node, int $namePos): void { * to the identifiers used by the Parser. Additionally it * maps T_OPEN_TAG_WITH_ECHO to T_ECHO and T_CLOSE_TAG to ';'. * - * @return array The token map + * @return array The token map */ protected function createTokenMap(): array { $tokenMap = []; diff --git a/lib/PhpParser/ParserFactory.php b/lib/PhpParser/ParserFactory.php index 307981e1bb..0e0133982f 100644 --- a/lib/PhpParser/ParserFactory.php +++ b/lib/PhpParser/ParserFactory.php @@ -38,6 +38,8 @@ public function create(int $kind, ?Lexer $lexer = null): Parser { * Create a parser targeting the given version on a best-effort basis. The parser will generally * accept code for the newest supported version, but will try to accommodate code that becomes * invalid in newer versions or changes in interpretation. + * + * @param array $lexerOptions Lexer options */ public function createForVersion(PhpVersion $version, array $lexerOptions = []): Parser { if ($version->isHostVersion()) { @@ -55,6 +57,8 @@ public function createForVersion(PhpVersion $version, array $lexerOptions = []): * Create a parser targeting the newest version supported by this library. Code for older * versions will be accepted if there have been no relevant backwards-compatibility breaks in * PHP. + * + * @param array $lexerOptions Lexer options */ public function createForNewestSupportedVersion(array $lexerOptions = []): Parser { return $this->createForVersion(PhpVersion::getNewestSupported(), $lexerOptions); @@ -63,6 +67,8 @@ public function createForNewestSupportedVersion(array $lexerOptions = []): Parse /** * Create a parser targeting the host PHP version, that is the PHP version we're currently * running on. This parser will not use any token emulation. + * + * @param array $lexerOptions Lexer options */ public function createForHostVersion(array $lexerOptions = []): Parser { return $this->createForVersion(PhpVersion::getHostVersion(), $lexerOptions); diff --git a/lib/PhpParser/PrettyPrinter/Standard.php b/lib/PhpParser/PrettyPrinter/Standard.php index 43b2e4a95d..1f0b9074b9 100644 --- a/lib/PhpParser/PrettyPrinter/Standard.php +++ b/lib/PhpParser/PrettyPrinter/Standard.php @@ -996,6 +996,7 @@ protected function pObjectProperty(Node $node): string { } } + /** @param (Expr|Node\InterpolatedStringPart)[] $encapsList */ protected function pEncapsList(array $encapsList, ?string $quote): string { $return = ''; foreach ($encapsList as $element) { @@ -1058,6 +1059,7 @@ protected function containsEndLabel(string $string, string $label, bool $atStart && preg_match('/' . $start . $label . $end . '/', $string); } + /** @param (Expr|Node\InterpolatedStringPart)[] $parts */ protected function encapsedContainsEndLabel(array $parts, string $label): bool { foreach ($parts as $i => $part) { $atStart = $i === 0; @@ -1105,6 +1107,7 @@ protected function hasNodeWithComments(array $nodes): bool { return false; } + /** @param Node[] $nodes */ protected function pMaybeMultiline(array $nodes, bool $trailingComma = false): string { if (!$this->hasNodeWithComments($nodes)) { return $this->pCommaSeparated($nodes); @@ -1113,6 +1116,7 @@ protected function pMaybeMultiline(array $nodes, bool $trailingComma = false): s } } + /** @param Node\AttributeGroup[] $nodes */ protected function pAttrGroups(array $nodes, bool $inline = false): string { $result = ''; $sep = $inline ? ' ' : $this->nl; diff --git a/lib/PhpParser/PrettyPrinterAbstract.php b/lib/PhpParser/PrettyPrinterAbstract.php index ab3f375270..3ee11d98dd 100644 --- a/lib/PhpParser/PrettyPrinterAbstract.php +++ b/lib/PhpParser/PrettyPrinterAbstract.php @@ -26,6 +26,7 @@ abstract class PrettyPrinterAbstract { protected const FIXUP_VAR_BRACED_NAME = 5; // Name operand that may require ${} bracing protected const FIXUP_ENCAPSED = 6; // Encapsed string part + /** @var array */ protected $precedenceMap = [ // [precedence, associativity] // where for precedence -1 is %left, 0 is %nonassoc and 1 is %right @@ -106,36 +107,40 @@ abstract class PrettyPrinterAbstract { /** @var TokenStream|null Original tokens for use in format-preserving pretty print */ protected $origTokens; - /** @var Internal\Differ|null Differ for node lists */ + /** @var Internal\Differ|null Differ for node lists */ protected $nodeListDiffer; - /** @var bool[] Map determining whether a certain character is a label character */ + /** @var array Map determining whether a certain character is a label character */ protected $labelCharMap; /** - * @var int[][] Map from token classes and subnode names to FIXUP_* constants. This is used - * during format-preserving prints to place additional parens/braces if necessary. + * @var array> Map from token classes and subnode names to FIXUP_* constants. + * This is used during format-preserving prints to place additional parens/braces if necessary. */ protected $fixupMap; /** - * @var (int|string)[][] Map from "{$node->getType()}->{$subNode}" to ['left' => $l, 'right' => $r], - * where $l and $r specify the token type that needs to be stripped when - * removing this node. + * @var array Map from "{$node->getType()}->{$subNode}" + * to ['left' => $l, 'right' => $r], where $l and $r specify the token type that needs to be stripped + * when removing this node. */ protected $removalMap; /** - * @var mixed[] Map from "{$node->getType()}->{$subNode}" to [$find, $beforeToken, $extraLeft, $extraRight]. - * $find is an optional token after which the insertion occurs. $extraLeft/Right - * are optionally added before/after the main insertions. + * @var array Map from + * "{$node->getType()}->{$subNode}" to [$find, $beforeToken, $extraLeft, $extraRight]. + * $find is an optional token after which the insertion occurs. $extraLeft/Right + * are optionally added before/after the main insertions. */ protected $insertionMap; /** - * @var string[] Map From "{$class}->{$subNode}" to string that should be inserted - * between elements of this list subnode. + * @var array Map From "{$class}->{$subNode}" to string that should be inserted + * between elements of this list subnode. */ protected $listInsertionMap; + /** + * @var array + */ protected $emptyListInsertionMap; - /** @var int[] Map from "{$class}->{$subNode}" to token before which the modifiers - * should be reprinted. */ + /** @var array Map from "{$class}->{$subNode}" to token before which the modifiers + * should be reprinted. */ protected $modifierChangeMap; /** @@ -152,7 +157,7 @@ abstract class PrettyPrinterAbstract { * syntax, if the node does not specify a format. Defaults to whether * the phpVersion support short array syntax. * - * @param array $options Dictionary of formatting options + * @param array{phpVersion?: PhpVersion, shortArraySyntax?: bool} $options Dictionary of formatting options */ public function __construct(array $options = []) { $this->phpVersion = $options['phpVersion'] ?? PhpVersion::fromComponents(7, 0); @@ -468,7 +473,7 @@ protected function pComments(array $comments): string { * * @param Node[] $stmts Modified AST with links to original AST * @param Node[] $origStmts Original AST with token offset information - * @param array $origTokens Tokens of the original code + * @param Token[] $origTokens Tokens of the original code * * @return string */ @@ -687,8 +692,8 @@ protected function p(Node $node, bool $parentFormatPreserved = false): string { /** * Perform a format-preserving pretty print of an array. * - * @param array $nodes New nodes - * @param array $origNodes Original nodes + * @param Node[] $nodes New nodes + * @param Node[] $origNodes Original nodes * @param int $pos Current token position (updated by reference) * @param int $indentAdjustment Adjustment for indentation * @param string $parentNodeClass Class of the containing node. @@ -1320,7 +1325,7 @@ protected function initializeInsertionMap(): void { 'Stmt_Class->extends' => [null, false, ' extends ', null], 'Stmt_Enum->scalarType' => [null, false, ' : ', null], 'Stmt_EnumCase->expr' => [null, false, ' = ', null], - 'Expr_PrintableNewAnonClass->extends' => [null, ' extends ', null], + 'Expr_PrintableNewAnonClass->extends' => [null, false, ' extends ', null], 'Stmt_Continue->num' => [\T_CONTINUE, false, ' ', null], 'Stmt_Foreach->keyVar' => [\T_AS, false, null, ' => '], 'Stmt_Function->returnType' => [')', false, ': ', null],