├── LICENSE ├── README.md ├── bin └── php-parse ├── composer.json └── lib └── PhpParser ├── Builder.php ├── Builder ├── ClassConst.php ├── Class_.php ├── Declaration.php ├── EnumCase.php ├── Enum_.php ├── FunctionLike.php ├── Function_.php ├── Interface_.php ├── Method.php ├── Namespace_.php ├── Param.php ├── Property.php ├── TraitUse.php ├── TraitUseAdaptation.php ├── Trait_.php └── Use_.php ├── BuilderFactory.php ├── BuilderHelpers.php ├── Comment.php ├── Comment └── Doc.php ├── ConstExprEvaluationException.php ├── ConstExprEvaluator.php ├── Error.php ├── ErrorHandler.php ├── ErrorHandler ├── Collecting.php └── Throwing.php ├── Internal ├── DiffElem.php ├── Differ.php ├── PrintableNewAnonClassNode.php ├── TokenPolyfill.php └── TokenStream.php ├── JsonDecoder.php ├── Lexer.php ├── Lexer ├── Emulative.php └── TokenEmulator │ ├── AsymmetricVisibilityTokenEmulator.php │ ├── AttributeEmulator.php │ ├── EnumTokenEmulator.php │ ├── ExplicitOctalEmulator.php │ ├── KeywordEmulator.php │ ├── MatchTokenEmulator.php │ ├── NullsafeTokenEmulator.php │ ├── PropertyTokenEmulator.php │ ├── ReadonlyFunctionTokenEmulator.php │ ├── ReadonlyTokenEmulator.php │ ├── ReverseEmulator.php │ └── TokenEmulator.php ├── Modifiers.php ├── NameContext.php ├── Node.php ├── Node ├── Arg.php ├── ArrayItem.php ├── Attribute.php ├── AttributeGroup.php ├── ClosureUse.php ├── ComplexType.php ├── Const_.php ├── DeclareItem.php ├── Expr.php ├── Expr │ ├── ArrayDimFetch.php │ ├── ArrayItem.php │ ├── Array_.php │ ├── ArrowFunction.php │ ├── Assign.php │ ├── AssignOp.php │ ├── AssignOp │ │ ├── BitwiseAnd.php │ │ ├── BitwiseOr.php │ │ ├── BitwiseXor.php │ │ ├── Coalesce.php │ │ ├── Concat.php │ │ ├── Div.php │ │ ├── Minus.php │ │ ├── Mod.php │ │ ├── Mul.php │ │ ├── Plus.php │ │ ├── Pow.php │ │ ├── ShiftLeft.php │ │ └── ShiftRight.php │ ├── AssignRef.php │ ├── BinaryOp.php │ ├── BinaryOp │ │ ├── BitwiseAnd.php │ │ ├── BitwiseOr.php │ │ ├── BitwiseXor.php │ │ ├── BooleanAnd.php │ │ ├── BooleanOr.php │ │ ├── Coalesce.php │ │ ├── Concat.php │ │ ├── Div.php │ │ ├── Equal.php │ │ ├── Greater.php │ │ ├── GreaterOrEqual.php │ │ ├── Identical.php │ │ ├── LogicalAnd.php │ │ ├── LogicalOr.php │ │ ├── LogicalXor.php │ │ ├── Minus.php │ │ ├── Mod.php │ │ ├── Mul.php │ │ ├── NotEqual.php │ │ ├── NotIdentical.php │ │ ├── Plus.php │ │ ├── Pow.php │ │ ├── ShiftLeft.php │ │ ├── ShiftRight.php │ │ ├── Smaller.php │ │ ├── SmallerOrEqual.php │ │ └── Spaceship.php │ ├── BitwiseNot.php │ ├── BooleanNot.php │ ├── CallLike.php │ ├── Cast.php │ ├── Cast │ │ ├── Array_.php │ │ ├── Bool_.php │ │ ├── Double.php │ │ ├── Int_.php │ │ ├── Object_.php │ │ ├── String_.php │ │ └── Unset_.php │ ├── ClassConstFetch.php │ ├── Clone_.php │ ├── Closure.php │ ├── ClosureUse.php │ ├── ConstFetch.php │ ├── Empty_.php │ ├── Error.php │ ├── ErrorSuppress.php │ ├── Eval_.php │ ├── Exit_.php │ ├── FuncCall.php │ ├── Include_.php │ ├── Instanceof_.php │ ├── Isset_.php │ ├── List_.php │ ├── Match_.php │ ├── MethodCall.php │ ├── New_.php │ ├── NullsafeMethodCall.php │ ├── NullsafePropertyFetch.php │ ├── PostDec.php │ ├── PostInc.php │ ├── PreDec.php │ ├── PreInc.php │ ├── Print_.php │ ├── PropertyFetch.php │ ├── ShellExec.php │ ├── StaticCall.php │ ├── StaticPropertyFetch.php │ ├── Ternary.php │ ├── Throw_.php │ ├── UnaryMinus.php │ ├── UnaryPlus.php │ ├── Variable.php │ ├── YieldFrom.php │ └── Yield_.php ├── FunctionLike.php ├── Identifier.php ├── InterpolatedStringPart.php ├── IntersectionType.php ├── MatchArm.php ├── Name.php ├── Name │ ├── FullyQualified.php │ └── Relative.php ├── NullableType.php ├── Param.php ├── PropertyHook.php ├── PropertyItem.php ├── Scalar.php ├── Scalar │ ├── DNumber.php │ ├── Encapsed.php │ ├── EncapsedStringPart.php │ ├── Float_.php │ ├── Int_.php │ ├── InterpolatedString.php │ ├── LNumber.php │ ├── MagicConst.php │ ├── MagicConst │ │ ├── Class_.php │ │ ├── Dir.php │ │ ├── File.php │ │ ├── Function_.php │ │ ├── Line.php │ │ ├── Method.php │ │ ├── Namespace_.php │ │ ├── Property.php │ │ └── Trait_.php │ └── String_.php ├── StaticVar.php ├── Stmt.php ├── Stmt │ ├── Block.php │ ├── Break_.php │ ├── Case_.php │ ├── Catch_.php │ ├── ClassConst.php │ ├── ClassLike.php │ ├── ClassMethod.php │ ├── Class_.php │ ├── Const_.php │ ├── Continue_.php │ ├── DeclareDeclare.php │ ├── Declare_.php │ ├── Do_.php │ ├── Echo_.php │ ├── ElseIf_.php │ ├── Else_.php │ ├── EnumCase.php │ ├── Enum_.php │ ├── Expression.php │ ├── Finally_.php │ ├── For_.php │ ├── Foreach_.php │ ├── Function_.php │ ├── Global_.php │ ├── Goto_.php │ ├── GroupUse.php │ ├── HaltCompiler.php │ ├── If_.php │ ├── InlineHTML.php │ ├── Interface_.php │ ├── Label.php │ ├── Namespace_.php │ ├── Nop.php │ ├── Property.php │ ├── PropertyProperty.php │ ├── Return_.php │ ├── StaticVar.php │ ├── Static_.php │ ├── Switch_.php │ ├── TraitUse.php │ ├── TraitUseAdaptation.php │ ├── TraitUseAdaptation │ │ ├── Alias.php │ │ └── Precedence.php │ ├── Trait_.php │ ├── TryCatch.php │ ├── Unset_.php │ ├── UseUse.php │ ├── Use_.php │ └── While_.php ├── UnionType.php ├── UseItem.php ├── VarLikeIdentifier.php └── VariadicPlaceholder.php ├── NodeAbstract.php ├── NodeDumper.php ├── NodeFinder.php ├── NodeTraverser.php ├── NodeTraverserInterface.php ├── NodeVisitor.php ├── NodeVisitor ├── CloningVisitor.php ├── CommentAnnotatingVisitor.php ├── FindingVisitor.php ├── FirstFindingVisitor.php ├── NameResolver.php ├── NodeConnectingVisitor.php └── ParentConnectingVisitor.php ├── NodeVisitorAbstract.php ├── Parser.php ├── Parser ├── Php7.php └── Php8.php ├── ParserAbstract.php ├── ParserFactory.php ├── PhpVersion.php ├── PrettyPrinter.php ├── PrettyPrinter └── Standard.php ├── PrettyPrinterAbstract.php ├── Token.php └── compatibility_tokens.php /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2011, Nikita Popov 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nikic/php-parser", 3 | "type": "library", 4 | "description": "A PHP parser written in PHP", 5 | "keywords": [ 6 | "php", 7 | "parser" 8 | ], 9 | "license": "BSD-3-Clause", 10 | "authors": [ 11 | { 12 | "name": "Nikita Popov" 13 | } 14 | ], 15 | "require": { 16 | "php": ">=7.4", 17 | "ext-tokenizer": "*", 18 | "ext-json": "*", 19 | "ext-ctype": "*" 20 | }, 21 | "require-dev": { 22 | "phpunit/phpunit": "^9.0", 23 | "ircmaxell/php-yacc": "^0.0.7" 24 | }, 25 | "extra": { 26 | "branch-alias": { 27 | "dev-master": "5.0-dev" 28 | } 29 | }, 30 | "autoload": { 31 | "psr-4": { 32 | "PhpParser\\": "lib/PhpParser" 33 | } 34 | }, 35 | "autoload-dev": { 36 | "psr-4": { 37 | "PhpParser\\": "test/PhpParser/" 38 | } 39 | }, 40 | "bin": [ 41 | "bin/php-parse" 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /lib/PhpParser/Builder.php: -------------------------------------------------------------------------------- 1 | */ 10 | protected array $attributes = []; 11 | 12 | /** 13 | * Adds a statement. 14 | * 15 | * @param PhpParser\Node\Stmt|PhpParser\Builder $stmt The statement to add 16 | * 17 | * @return $this The builder instance (for fluid interface) 18 | */ 19 | abstract public function addStmt($stmt); 20 | 21 | /** 22 | * Adds multiple statements. 23 | * 24 | * @param (PhpParser\Node\Stmt|PhpParser\Builder)[] $stmts The statements to add 25 | * 26 | * @return $this The builder instance (for fluid interface) 27 | */ 28 | public function addStmts(array $stmts) { 29 | foreach ($stmts as $stmt) { 30 | $this->addStmt($stmt); 31 | } 32 | 33 | return $this; 34 | } 35 | 36 | /** 37 | * Sets doc comment for the declaration. 38 | * 39 | * @param PhpParser\Comment\Doc|string $docComment Doc comment to set 40 | * 41 | * @return $this The builder instance (for fluid interface) 42 | */ 43 | public function setDocComment($docComment) { 44 | $this->attributes['comments'] = [ 45 | BuilderHelpers::normalizeDocComment($docComment) 46 | ]; 47 | 48 | return $this; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /lib/PhpParser/Builder/EnumCase.php: -------------------------------------------------------------------------------- 1 | */ 18 | protected array $attributes = []; 19 | 20 | /** @var list */ 21 | protected array $attributeGroups = []; 22 | 23 | /** 24 | * Creates an enum case builder. 25 | * 26 | * @param string|Identifier $name Name 27 | */ 28 | public function __construct($name) { 29 | $this->name = $name; 30 | } 31 | 32 | /** 33 | * Sets the value. 34 | * 35 | * @param Node\Expr|string|int $value 36 | * 37 | * @return $this 38 | */ 39 | public function setValue($value) { 40 | $this->value = BuilderHelpers::normalizeValue($value); 41 | 42 | return $this; 43 | } 44 | 45 | /** 46 | * Sets doc comment for the constant. 47 | * 48 | * @param PhpParser\Comment\Doc|string $docComment Doc comment to set 49 | * 50 | * @return $this The builder instance (for fluid interface) 51 | */ 52 | public function setDocComment($docComment) { 53 | $this->attributes = [ 54 | 'comments' => [BuilderHelpers::normalizeDocComment($docComment)] 55 | ]; 56 | 57 | return $this; 58 | } 59 | 60 | /** 61 | * Adds an attribute group. 62 | * 63 | * @param Node\Attribute|Node\AttributeGroup $attribute 64 | * 65 | * @return $this The builder instance (for fluid interface) 66 | */ 67 | public function addAttribute($attribute) { 68 | $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); 69 | 70 | return $this; 71 | } 72 | 73 | /** 74 | * Returns the built enum case node. 75 | * 76 | * @return Stmt\EnumCase The built constant node 77 | */ 78 | public function getNode(): PhpParser\Node { 79 | return new Stmt\EnumCase( 80 | $this->name, 81 | $this->value, 82 | $this->attributeGroups, 83 | $this->attributes 84 | ); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /lib/PhpParser/Builder/FunctionLike.php: -------------------------------------------------------------------------------- 1 | returnByRef = true; 23 | 24 | return $this; 25 | } 26 | 27 | /** 28 | * Adds a parameter. 29 | * 30 | * @param Node\Param|Param $param The parameter to add 31 | * 32 | * @return $this The builder instance (for fluid interface) 33 | */ 34 | public function addParam($param) { 35 | $param = BuilderHelpers::normalizeNode($param); 36 | 37 | if (!$param instanceof Node\Param) { 38 | throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType())); 39 | } 40 | 41 | $this->params[] = $param; 42 | 43 | return $this; 44 | } 45 | 46 | /** 47 | * Adds multiple parameters. 48 | * 49 | * @param (Node\Param|Param)[] $params The parameters to add 50 | * 51 | * @return $this The builder instance (for fluid interface) 52 | */ 53 | public function addParams(array $params) { 54 | foreach ($params as $param) { 55 | $this->addParam($param); 56 | } 57 | 58 | return $this; 59 | } 60 | 61 | /** 62 | * Sets the return type for PHP 7. 63 | * 64 | * @param string|Node\Name|Node\Identifier|Node\ComplexType $type 65 | * 66 | * @return $this The builder instance (for fluid interface) 67 | */ 68 | public function setReturnType($type) { 69 | $this->returnType = BuilderHelpers::normalizeType($type); 70 | 71 | return $this; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /lib/PhpParser/Builder/Function_.php: -------------------------------------------------------------------------------- 1 | */ 13 | protected array $stmts = []; 14 | 15 | /** @var list */ 16 | protected array $attributeGroups = []; 17 | 18 | /** 19 | * Creates a function builder. 20 | * 21 | * @param string $name Name of the function 22 | */ 23 | public function __construct(string $name) { 24 | $this->name = $name; 25 | } 26 | 27 | /** 28 | * Adds a statement. 29 | * 30 | * @param Node|PhpParser\Builder $stmt The statement to add 31 | * 32 | * @return $this The builder instance (for fluid interface) 33 | */ 34 | public function addStmt($stmt) { 35 | $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); 36 | 37 | return $this; 38 | } 39 | 40 | /** 41 | * Adds an attribute group. 42 | * 43 | * @param Node\Attribute|Node\AttributeGroup $attribute 44 | * 45 | * @return $this The builder instance (for fluid interface) 46 | */ 47 | public function addAttribute($attribute) { 48 | $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); 49 | 50 | return $this; 51 | } 52 | 53 | /** 54 | * Returns the built function node. 55 | * 56 | * @return Stmt\Function_ The built function node 57 | */ 58 | public function getNode(): Node { 59 | return new Stmt\Function_($this->name, [ 60 | 'byRef' => $this->returnByRef, 61 | 'params' => $this->params, 62 | 'returnType' => $this->returnType, 63 | 'stmts' => $this->stmts, 64 | 'attrGroups' => $this->attributeGroups, 65 | ], $this->attributes); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /lib/PhpParser/Builder/Namespace_.php: -------------------------------------------------------------------------------- 1 | name = null !== $name ? BuilderHelpers::normalizeName($name) : null; 22 | } 23 | 24 | /** 25 | * Adds a statement. 26 | * 27 | * @param Node|PhpParser\Builder $stmt The statement to add 28 | * 29 | * @return $this The builder instance (for fluid interface) 30 | */ 31 | public function addStmt($stmt) { 32 | $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); 33 | 34 | return $this; 35 | } 36 | 37 | /** 38 | * Returns the built node. 39 | * 40 | * @return Stmt\Namespace_ The built node 41 | */ 42 | public function getNode(): Node { 43 | return new Stmt\Namespace_($this->name, $this->stmts, $this->attributes); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/PhpParser/Builder/TraitUse.php: -------------------------------------------------------------------------------- 1 | and($trait); 24 | } 25 | } 26 | 27 | /** 28 | * Adds used trait. 29 | * 30 | * @param Node\Name|string $trait Trait name 31 | * 32 | * @return $this The builder instance (for fluid interface) 33 | */ 34 | public function and($trait) { 35 | $this->traits[] = BuilderHelpers::normalizeName($trait); 36 | return $this; 37 | } 38 | 39 | /** 40 | * Adds trait adaptation. 41 | * 42 | * @param Stmt\TraitUseAdaptation|Builder\TraitUseAdaptation $adaptation Trait adaptation 43 | * 44 | * @return $this The builder instance (for fluid interface) 45 | */ 46 | public function with($adaptation) { 47 | $adaptation = BuilderHelpers::normalizeNode($adaptation); 48 | 49 | if (!$adaptation instanceof Stmt\TraitUseAdaptation) { 50 | throw new \LogicException('Adaptation must have type TraitUseAdaptation'); 51 | } 52 | 53 | $this->adaptations[] = $adaptation; 54 | return $this; 55 | } 56 | 57 | /** 58 | * Returns the built node. 59 | * 60 | * @return Node The built node 61 | */ 62 | public function getNode(): Node { 63 | return new Stmt\TraitUse($this->traits, $this->adaptations); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /lib/PhpParser/Builder/Trait_.php: -------------------------------------------------------------------------------- 1 | */ 13 | protected array $uses = []; 14 | /** @var list */ 15 | protected array $constants = []; 16 | /** @var list */ 17 | protected array $properties = []; 18 | /** @var list */ 19 | protected array $methods = []; 20 | /** @var list */ 21 | protected array $attributeGroups = []; 22 | 23 | /** 24 | * Creates an interface builder. 25 | * 26 | * @param string $name Name of the interface 27 | */ 28 | public function __construct(string $name) { 29 | $this->name = $name; 30 | } 31 | 32 | /** 33 | * Adds a statement. 34 | * 35 | * @param Stmt|PhpParser\Builder $stmt The statement to add 36 | * 37 | * @return $this The builder instance (for fluid interface) 38 | */ 39 | public function addStmt($stmt) { 40 | $stmt = BuilderHelpers::normalizeNode($stmt); 41 | 42 | if ($stmt instanceof Stmt\Property) { 43 | $this->properties[] = $stmt; 44 | } elseif ($stmt instanceof Stmt\ClassMethod) { 45 | $this->methods[] = $stmt; 46 | } elseif ($stmt instanceof Stmt\TraitUse) { 47 | $this->uses[] = $stmt; 48 | } elseif ($stmt instanceof Stmt\ClassConst) { 49 | $this->constants[] = $stmt; 50 | } else { 51 | throw new \LogicException(sprintf('Unexpected node of type "%s"', $stmt->getType())); 52 | } 53 | 54 | return $this; 55 | } 56 | 57 | /** 58 | * Adds an attribute group. 59 | * 60 | * @param Node\Attribute|Node\AttributeGroup $attribute 61 | * 62 | * @return $this The builder instance (for fluid interface) 63 | */ 64 | public function addAttribute($attribute) { 65 | $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); 66 | 67 | return $this; 68 | } 69 | 70 | /** 71 | * Returns the built trait node. 72 | * 73 | * @return Stmt\Trait_ The built interface node 74 | */ 75 | public function getNode(): PhpParser\Node { 76 | return new Stmt\Trait_( 77 | $this->name, [ 78 | 'stmts' => array_merge($this->uses, $this->constants, $this->properties, $this->methods), 79 | 'attrGroups' => $this->attributeGroups, 80 | ], $this->attributes 81 | ); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /lib/PhpParser/Builder/Use_.php: -------------------------------------------------------------------------------- 1 | name = BuilderHelpers::normalizeName($name); 24 | $this->type = $type; 25 | } 26 | 27 | /** 28 | * Sets alias for used name. 29 | * 30 | * @param string $alias Alias to use (last component of full name by default) 31 | * 32 | * @return $this The builder instance (for fluid interface) 33 | */ 34 | public function as(string $alias) { 35 | $this->alias = $alias; 36 | return $this; 37 | } 38 | 39 | /** 40 | * Returns the built node. 41 | * 42 | * @return Stmt\Use_ The built node 43 | */ 44 | public function getNode(): Node { 45 | return new Stmt\Use_([ 46 | new Node\UseItem($this->name, $this->alias) 47 | ], $this->type); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/PhpParser/Comment/Doc.php: -------------------------------------------------------------------------------- 1 | errors[] = $error; 19 | } 20 | 21 | /** 22 | * Get collected errors. 23 | * 24 | * @return Error[] 25 | */ 26 | public function getErrors(): array { 27 | return $this->errors; 28 | } 29 | 30 | /** 31 | * Check whether there are any errors. 32 | */ 33 | public function hasErrors(): bool { 34 | return !empty($this->errors); 35 | } 36 | 37 | /** 38 | * Reset/clear collected errors. 39 | */ 40 | public function clearErrors(): void { 41 | $this->errors = []; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lib/PhpParser/ErrorHandler/Throwing.php: -------------------------------------------------------------------------------- 1 | type = $type; 28 | $this->old = $old; 29 | $this->new = $new; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/PhpParser/Internal/PrintableNewAnonClassNode.php: -------------------------------------------------------------------------------- 1 | $attributes Attributes 39 | */ 40 | public function __construct( 41 | array $attrGroups, int $flags, array $args, ?Node\Name $extends, array $implements, 42 | array $stmts, array $attributes 43 | ) { 44 | parent::__construct($attributes); 45 | $this->attrGroups = $attrGroups; 46 | $this->flags = $flags; 47 | $this->args = $args; 48 | $this->extends = $extends; 49 | $this->implements = $implements; 50 | $this->stmts = $stmts; 51 | } 52 | 53 | public static function fromNewNode(Expr\New_ $newNode): self { 54 | $class = $newNode->class; 55 | assert($class instanceof Node\Stmt\Class_); 56 | // We don't assert that $class->name is null here, to allow consumers to assign unique names 57 | // to anonymous classes for their own purposes. We simplify ignore the name here. 58 | return new self( 59 | $class->attrGroups, $class->flags, $newNode->args, $class->extends, $class->implements, 60 | $class->stmts, $newNode->getAttributes() 61 | ); 62 | } 63 | 64 | public function getType(): string { 65 | return 'Expr_PrintableNewAnonClass'; 66 | } 67 | 68 | public function getSubNodeNames(): array { 69 | return ['attrGroups', 'flags', 'args', 'extends', 'implements', 'stmts']; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /lib/PhpParser/Lexer/TokenEmulator/AttributeEmulator.php: -------------------------------------------------------------------------------- 1 | text === '#' && isset($tokens[$i + 1]) && $tokens[$i + 1]->text === '[') { 23 | array_splice($tokens, $i, 2, [ 24 | new Token(\T_ATTRIBUTE, '#[', $token->line, $token->pos), 25 | ]); 26 | $c--; 27 | continue; 28 | } 29 | } 30 | 31 | return $tokens; 32 | } 33 | 34 | public function reverseEmulate(string $code, array $tokens): array { 35 | // TODO 36 | return $tokens; 37 | } 38 | 39 | public function preprocessCode(string $code, array &$patches): string { 40 | $pos = 0; 41 | while (false !== $pos = strpos($code, '#[', $pos)) { 42 | // Replace #[ with %[ 43 | $code[$pos] = '%'; 44 | $patches[] = [$pos, 'replace', '#']; 45 | $pos += 2; 46 | } 47 | return $code; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/PhpParser/Lexer/TokenEmulator/EnumTokenEmulator.php: -------------------------------------------------------------------------------- 1 | id === \T_WHITESPACE 24 | && $tokens[$pos + 2]->id === \T_STRING; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/PhpParser/Lexer/TokenEmulator/ExplicitOctalEmulator.php: -------------------------------------------------------------------------------- 1 | id == \T_LNUMBER && $token->text === '0' && 21 | isset($tokens[$i + 1]) && $tokens[$i + 1]->id == \T_STRING && 22 | preg_match('/[oO][0-7]+(?:_[0-7]+)*/', $tokens[$i + 1]->text) 23 | ) { 24 | $tokenKind = $this->resolveIntegerOrFloatToken($tokens[$i + 1]->text); 25 | array_splice($tokens, $i, 2, [ 26 | new Token($tokenKind, '0' . $tokens[$i + 1]->text, $token->line, $token->pos), 27 | ]); 28 | $c--; 29 | } 30 | } 31 | return $tokens; 32 | } 33 | 34 | private function resolveIntegerOrFloatToken(string $str): int { 35 | $str = substr($str, 1); 36 | $str = str_replace('_', '', $str); 37 | $num = octdec($str); 38 | return is_float($num) ? \T_DNUMBER : \T_LNUMBER; 39 | } 40 | 41 | public function reverseEmulate(string $code, array $tokens): array { 42 | // Explicit octals were not legal code previously, don't bother. 43 | return $tokens; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/PhpParser/Lexer/TokenEmulator/KeywordEmulator.php: -------------------------------------------------------------------------------- 1 | getKeywordString()) !== false; 13 | } 14 | 15 | /** @param Token[] $tokens */ 16 | protected function isKeywordContext(array $tokens, int $pos): bool { 17 | $prevToken = $this->getPreviousNonSpaceToken($tokens, $pos); 18 | if ($prevToken === null) { 19 | return false; 20 | } 21 | return $prevToken->id !== \T_OBJECT_OPERATOR 22 | && $prevToken->id !== \T_NULLSAFE_OBJECT_OPERATOR; 23 | } 24 | 25 | public function emulate(string $code, array $tokens): array { 26 | $keywordString = $this->getKeywordString(); 27 | foreach ($tokens as $i => $token) { 28 | if ($token->id === T_STRING && strtolower($token->text) === $keywordString 29 | && $this->isKeywordContext($tokens, $i)) { 30 | $token->id = $this->getKeywordToken(); 31 | } 32 | } 33 | 34 | return $tokens; 35 | } 36 | 37 | /** @param Token[] $tokens */ 38 | private function getPreviousNonSpaceToken(array $tokens, int $start): ?Token { 39 | for ($i = $start - 1; $i >= 0; --$i) { 40 | if ($tokens[$i]->id === T_WHITESPACE) { 41 | continue; 42 | } 43 | 44 | return $tokens[$i]; 45 | } 46 | 47 | return null; 48 | } 49 | 50 | public function reverseEmulate(string $code, array $tokens): array { 51 | $keywordToken = $this->getKeywordToken(); 52 | foreach ($tokens as $token) { 53 | if ($token->id === $keywordToken) { 54 | $token->id = \T_STRING; 55 | } 56 | } 57 | 58 | return $tokens; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/PhpParser/Lexer/TokenEmulator/MatchTokenEmulator.php: -------------------------------------------------------------------------------- 1 | ') !== false; 15 | } 16 | 17 | public function emulate(string $code, array $tokens): array { 18 | // We need to manually iterate and manage a count because we'll change 19 | // the tokens array on the way 20 | for ($i = 0, $c = count($tokens); $i < $c; ++$i) { 21 | $token = $tokens[$i]; 22 | if ($token->text === '?' && isset($tokens[$i + 1]) && $tokens[$i + 1]->id === \T_OBJECT_OPERATOR) { 23 | array_splice($tokens, $i, 2, [ 24 | new Token(\T_NULLSAFE_OBJECT_OPERATOR, '?->', $token->line, $token->pos), 25 | ]); 26 | $c--; 27 | continue; 28 | } 29 | 30 | // Handle ?-> inside encapsed string. 31 | if ($token->id === \T_ENCAPSED_AND_WHITESPACE && isset($tokens[$i - 1]) 32 | && $tokens[$i - 1]->id === \T_VARIABLE 33 | && preg_match('/^\?->([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/', $token->text, $matches) 34 | ) { 35 | $replacement = [ 36 | new Token(\T_NULLSAFE_OBJECT_OPERATOR, '?->', $token->line, $token->pos), 37 | new Token(\T_STRING, $matches[1], $token->line, $token->pos + 3), 38 | ]; 39 | $matchLen = \strlen($matches[0]); 40 | if ($matchLen !== \strlen($token->text)) { 41 | $replacement[] = new Token( 42 | \T_ENCAPSED_AND_WHITESPACE, 43 | \substr($token->text, $matchLen), 44 | $token->line, $token->pos + $matchLen 45 | ); 46 | } 47 | array_splice($tokens, $i, 1, $replacement); 48 | $c += \count($replacement) - 1; 49 | continue; 50 | } 51 | } 52 | 53 | return $tokens; 54 | } 55 | 56 | public function reverseEmulate(string $code, array $tokens): array { 57 | // ?-> was not valid code previously, don't bother. 58 | return $tokens; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/PhpParser/Lexer/TokenEmulator/PropertyTokenEmulator.php: -------------------------------------------------------------------------------- 1 | text === '(' || 27 | ($tokens[$pos + 1]->id === \T_WHITESPACE && 28 | isset($tokens[$pos + 2]) && 29 | $tokens[$pos + 2]->text === '('))); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/PhpParser/Lexer/TokenEmulator/ReverseEmulator.php: -------------------------------------------------------------------------------- 1 | emulator = $emulator; 16 | } 17 | 18 | public function getPhpVersion(): PhpVersion { 19 | return $this->emulator->getPhpVersion(); 20 | } 21 | 22 | public function isEmulationNeeded(string $code): bool { 23 | return $this->emulator->isEmulationNeeded($code); 24 | } 25 | 26 | public function emulate(string $code, array $tokens): array { 27 | return $this->emulator->reverseEmulate($code, $tokens); 28 | } 29 | 30 | public function reverseEmulate(string $code, array $tokens): array { 31 | return $this->emulator->emulate($code, $tokens); 32 | } 33 | 34 | public function preprocessCode(string $code, array &$patches): string { 35 | return $code; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/PhpParser/Lexer/TokenEmulator/TokenEmulator.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 24 | * @param Identifier|null $name Parameter name (for named parameters) 25 | */ 26 | public function __construct( 27 | Expr $value, bool $byRef = false, bool $unpack = false, array $attributes = [], 28 | ?Identifier $name = null 29 | ) { 30 | $this->attributes = $attributes; 31 | $this->name = $name; 32 | $this->value = $value; 33 | $this->byRef = $byRef; 34 | $this->unpack = $unpack; 35 | } 36 | 37 | public function getSubNodeNames(): array { 38 | return ['name', 'value', 'byRef', 'unpack']; 39 | } 40 | 41 | public function getType(): string { 42 | return 'Arg'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/ArrayItem.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 24 | */ 25 | public function __construct(Expr $value, ?Expr $key = null, bool $byRef = false, array $attributes = [], bool $unpack = false) { 26 | $this->attributes = $attributes; 27 | $this->key = $key; 28 | $this->value = $value; 29 | $this->byRef = $byRef; 30 | $this->unpack = $unpack; 31 | } 32 | 33 | public function getSubNodeNames(): array { 34 | return ['key', 'value', 'byRef', 'unpack']; 35 | } 36 | 37 | public function getType(): string { 38 | return 'ArrayItem'; 39 | } 40 | } 41 | 42 | // @deprecated compatibility alias 43 | class_alias(ArrayItem::class, Expr\ArrayItem::class); 44 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Attribute.php: -------------------------------------------------------------------------------- 1 | Attribute arguments */ 13 | public array $args; 14 | 15 | /** 16 | * @param Node\Name $name Attribute name 17 | * @param list $args Attribute arguments 18 | * @param array $attributes Additional node attributes 19 | */ 20 | public function __construct(Name $name, array $args = [], array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->name = $name; 23 | $this->args = $args; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['name', 'args']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Attribute'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/AttributeGroup.php: -------------------------------------------------------------------------------- 1 | $attributes Additional node attributes 14 | */ 15 | public function __construct(array $attrs, array $attributes = []) { 16 | $this->attributes = $attributes; 17 | $this->attrs = $attrs; 18 | } 19 | 20 | public function getSubNodeNames(): array { 21 | return ['attrs']; 22 | } 23 | 24 | public function getType(): string { 25 | return 'AttributeGroup'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/ClosureUse.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(Expr\Variable $var, bool $byRef = false, array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->var = $var; 23 | $this->byRef = $byRef; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['var', 'byRef']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'ClosureUse'; 32 | } 33 | } 34 | 35 | // @deprecated compatibility alias 36 | class_alias(ClosureUse::class, Expr\ClosureUse::class); 37 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/ComplexType.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 22 | */ 23 | public function __construct($name, Expr $value, array $attributes = []) { 24 | $this->attributes = $attributes; 25 | $this->name = \is_string($name) ? new Identifier($name) : $name; 26 | $this->value = $value; 27 | } 28 | 29 | public function getSubNodeNames(): array { 30 | return ['name', 'value']; 31 | } 32 | 33 | public function getType(): string { 34 | return 'Const'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/DeclareItem.php: -------------------------------------------------------------------------------- 1 | value pair node. 16 | * 17 | * @param string|Node\Identifier $key Key 18 | * @param Node\Expr $value Value 19 | * @param array $attributes Additional attributes 20 | */ 21 | public function __construct($key, Node\Expr $value, array $attributes = []) { 22 | $this->attributes = $attributes; 23 | $this->key = \is_string($key) ? new Node\Identifier($key) : $key; 24 | $this->value = $value; 25 | } 26 | 27 | public function getSubNodeNames(): array { 28 | return ['key', 'value']; 29 | } 30 | 31 | public function getType(): string { 32 | return 'DeclareItem'; 33 | } 34 | } 35 | 36 | // @deprecated compatibility alias 37 | class_alias(DeclareItem::class, Stmt\DeclareDeclare::class); 38 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(Expr $var, ?Expr $dim = null, array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->var = $var; 23 | $this->dim = $dim; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['var', 'dim']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Expr_ArrayDimFetch'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/ArrayItem.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 21 | */ 22 | public function __construct(array $items = [], array $attributes = []) { 23 | $this->attributes = $attributes; 24 | $this->items = $items; 25 | } 26 | 27 | public function getSubNodeNames(): array { 28 | return ['items']; 29 | } 30 | 31 | public function getType(): string { 32 | return 'Expr_Array'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/ArrowFunction.php: -------------------------------------------------------------------------------- 1 | false : Whether the closure is static 38 | * 'byRef' => false : Whether to return by reference 39 | * 'params' => array() : Parameters 40 | * 'returnType' => null : Return type 41 | * 'attrGroups' => array() : PHP attribute groups 42 | * @param array $attributes Additional attributes 43 | */ 44 | public function __construct(array $subNodes, array $attributes = []) { 45 | $this->attributes = $attributes; 46 | $this->static = $subNodes['static'] ?? false; 47 | $this->byRef = $subNodes['byRef'] ?? false; 48 | $this->params = $subNodes['params'] ?? []; 49 | $this->returnType = $subNodes['returnType'] ?? null; 50 | $this->expr = $subNodes['expr']; 51 | $this->attrGroups = $subNodes['attrGroups'] ?? []; 52 | } 53 | 54 | public function getSubNodeNames(): array { 55 | return ['attrGroups', 'static', 'byRef', 'params', 'returnType', 'expr']; 56 | } 57 | 58 | public function returnsByRef(): bool { 59 | return $this->byRef; 60 | } 61 | 62 | public function getParams(): array { 63 | return $this->params; 64 | } 65 | 66 | public function getReturnType() { 67 | return $this->returnType; 68 | } 69 | 70 | public function getAttrGroups(): array { 71 | return $this->attrGroups; 72 | } 73 | 74 | /** 75 | * @return Node\Stmt\Return_[] 76 | */ 77 | public function getStmts(): array { 78 | return [new Node\Stmt\Return_($this->expr)]; 79 | } 80 | 81 | public function getType(): string { 82 | return 'Expr_ArrowFunction'; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Assign.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(Expr $var, Expr $expr, array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->var = $var; 23 | $this->expr = $expr; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['var', 'expr']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Expr_Assign'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/AssignOp.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(Expr $var, Expr $expr, array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->var = $var; 23 | $this->expr = $expr; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['var', 'expr']; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/AssignOp/BitwiseAnd.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(Expr $var, Expr $expr, array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->var = $var; 23 | $this->expr = $expr; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['var', 'expr']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Expr_AssignRef'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/BinaryOp.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(Expr $left, Expr $right, array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->left = $left; 23 | $this->right = $right; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['left', 'right']; 28 | } 29 | 30 | /** 31 | * Get the operator sigil for this binary operation. 32 | * 33 | * In the case there are multiple possible sigils for an operator, this method does not 34 | * necessarily return the one used in the parsed code. 35 | */ 36 | abstract public function getOperatorSigil(): string; 37 | } 38 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/BinaryOp/BitwiseAnd.php: -------------------------------------------------------------------------------- 1 | '; 10 | } 11 | 12 | public function getType(): string { 13 | return 'Expr_BinaryOp_Greater'; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/BinaryOp/GreaterOrEqual.php: -------------------------------------------------------------------------------- 1 | ='; 10 | } 11 | 12 | public function getType(): string { 13 | return 'Expr_BinaryOp_GreaterOrEqual'; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/BinaryOp/Identical.php: -------------------------------------------------------------------------------- 1 | >'; 10 | } 11 | 12 | public function getType(): string { 13 | return 'Expr_BinaryOp_ShiftRight'; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/BinaryOp/Smaller.php: -------------------------------------------------------------------------------- 1 | '; 10 | } 11 | 12 | public function getType(): string { 13 | return 'Expr_BinaryOp_Spaceship'; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/BitwiseNot.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_BitwiseNot'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/BooleanNot.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_BooleanNot'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/CallLike.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | abstract public function getRawArgs(): array; 17 | 18 | /** 19 | * Returns whether this call expression is actually a first class callable. 20 | */ 21 | public function isFirstClassCallable(): bool { 22 | $rawArgs = $this->getRawArgs(); 23 | return count($rawArgs) === 1 && current($rawArgs) instanceof VariadicPlaceholder; 24 | } 25 | 26 | /** 27 | * Assert that this is not a first-class callable and return only ordinary Args. 28 | * 29 | * @return Arg[] 30 | */ 31 | public function getArgs(): array { 32 | assert(!$this->isFirstClassCallable()); 33 | return $this->getRawArgs(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Cast.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Cast/Array_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 22 | */ 23 | public function __construct(Node $class, $name, array $attributes = []) { 24 | $this->attributes = $attributes; 25 | $this->class = $class; 26 | $this->name = \is_string($name) ? new Identifier($name) : $name; 27 | } 28 | 29 | public function getSubNodeNames(): array { 30 | return ['class', 'name']; 31 | } 32 | 33 | public function getType(): string { 34 | return 'Expr_ClassConstFetch'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Clone_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_Clone'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/ClosureUse.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 17 | */ 18 | public function __construct(Name $name, array $attributes = []) { 19 | $this->attributes = $attributes; 20 | $this->name = $name; 21 | } 22 | 23 | public function getSubNodeNames(): array { 24 | return ['name']; 25 | } 26 | 27 | public function getType(): string { 28 | return 'Expr_ConstFetch'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Empty_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_Empty'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Error.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 18 | */ 19 | public function __construct(array $attributes = []) { 20 | $this->attributes = $attributes; 21 | } 22 | 23 | public function getSubNodeNames(): array { 24 | return []; 25 | } 26 | 27 | public function getType(): string { 28 | return 'Expr_Error'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/ErrorSuppress.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_ErrorSuppress'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Eval_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_Eval'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Exit_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 20 | */ 21 | public function __construct(?Expr $expr = null, array $attributes = []) { 22 | $this->attributes = $attributes; 23 | $this->expr = $expr; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['expr']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Expr_Exit'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/FuncCall.php: -------------------------------------------------------------------------------- 1 | Arguments */ 12 | public array $args; 13 | 14 | /** 15 | * Constructs a function call node. 16 | * 17 | * @param Node\Name|Expr $name Function name 18 | * @param array $args Arguments 19 | * @param array $attributes Additional attributes 20 | */ 21 | public function __construct(Node $name, array $args = [], array $attributes = []) { 22 | $this->attributes = $attributes; 23 | $this->name = $name; 24 | $this->args = $args; 25 | } 26 | 27 | public function getSubNodeNames(): array { 28 | return ['name', 'args']; 29 | } 30 | 31 | public function getType(): string { 32 | return 'Expr_FuncCall'; 33 | } 34 | 35 | public function getRawArgs(): array { 36 | return $this->args; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Include_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 24 | */ 25 | public function __construct(Expr $expr, int $type, array $attributes = []) { 26 | $this->attributes = $attributes; 27 | $this->expr = $expr; 28 | $this->type = $type; 29 | } 30 | 31 | public function getSubNodeNames(): array { 32 | return ['expr', 'type']; 33 | } 34 | 35 | public function getType(): string { 36 | return 'Expr_Include'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Instanceof_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 21 | */ 22 | public function __construct(Expr $expr, Node $class, array $attributes = []) { 23 | $this->attributes = $attributes; 24 | $this->expr = $expr; 25 | $this->class = $class; 26 | } 27 | 28 | public function getSubNodeNames(): array { 29 | return ['expr', 'class']; 30 | } 31 | 32 | public function getType(): string { 33 | return 'Expr_Instanceof'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Isset_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(array $vars, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->vars = $vars; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['vars']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_Isset'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/List_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 21 | */ 22 | public function __construct(array $items, array $attributes = []) { 23 | $this->attributes = $attributes; 24 | $this->items = $items; 25 | } 26 | 27 | public function getSubNodeNames(): array { 28 | return ['items']; 29 | } 30 | 31 | public function getType(): string { 32 | return 'Expr_List'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Match_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 18 | */ 19 | public function __construct(Node\Expr $cond, array $arms = [], array $attributes = []) { 20 | $this->attributes = $attributes; 21 | $this->cond = $cond; 22 | $this->arms = $arms; 23 | } 24 | 25 | public function getSubNodeNames(): array { 26 | return ['cond', 'arms']; 27 | } 28 | 29 | public function getType(): string { 30 | return 'Expr_Match'; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/MethodCall.php: -------------------------------------------------------------------------------- 1 | Arguments */ 17 | public array $args; 18 | 19 | /** 20 | * Constructs a function call node. 21 | * 22 | * @param Expr $var Variable holding object 23 | * @param string|Identifier|Expr $name Method name 24 | * @param array $args Arguments 25 | * @param array $attributes Additional attributes 26 | */ 27 | public function __construct(Expr $var, $name, array $args = [], array $attributes = []) { 28 | $this->attributes = $attributes; 29 | $this->var = $var; 30 | $this->name = \is_string($name) ? new Identifier($name) : $name; 31 | $this->args = $args; 32 | } 33 | 34 | public function getSubNodeNames(): array { 35 | return ['var', 'name', 'args']; 36 | } 37 | 38 | public function getType(): string { 39 | return 'Expr_MethodCall'; 40 | } 41 | 42 | public function getRawArgs(): array { 43 | return $this->args; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/New_.php: -------------------------------------------------------------------------------- 1 | Arguments */ 14 | public array $args; 15 | 16 | /** 17 | * Constructs a function call node. 18 | * 19 | * @param Node\Name|Expr|Node\Stmt\Class_ $class Class name (or class node for anonymous classes) 20 | * @param array $args Arguments 21 | * @param array $attributes Additional attributes 22 | */ 23 | public function __construct(Node $class, array $args = [], array $attributes = []) { 24 | $this->attributes = $attributes; 25 | $this->class = $class; 26 | $this->args = $args; 27 | } 28 | 29 | public function getSubNodeNames(): array { 30 | return ['class', 'args']; 31 | } 32 | 33 | public function getType(): string { 34 | return 'Expr_New'; 35 | } 36 | 37 | public function getRawArgs(): array { 38 | return $this->args; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/NullsafeMethodCall.php: -------------------------------------------------------------------------------- 1 | Arguments */ 17 | public array $args; 18 | 19 | /** 20 | * Constructs a nullsafe method call node. 21 | * 22 | * @param Expr $var Variable holding object 23 | * @param string|Identifier|Expr $name Method name 24 | * @param array $args Arguments 25 | * @param array $attributes Additional attributes 26 | */ 27 | public function __construct(Expr $var, $name, array $args = [], array $attributes = []) { 28 | $this->attributes = $attributes; 29 | $this->var = $var; 30 | $this->name = \is_string($name) ? new Identifier($name) : $name; 31 | $this->args = $args; 32 | } 33 | 34 | public function getSubNodeNames(): array { 35 | return ['var', 'name', 'args']; 36 | } 37 | 38 | public function getType(): string { 39 | return 'Expr_NullsafeMethodCall'; 40 | } 41 | 42 | public function getRawArgs(): array { 43 | return $this->args; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/NullsafePropertyFetch.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 21 | */ 22 | public function __construct(Expr $var, $name, array $attributes = []) { 23 | $this->attributes = $attributes; 24 | $this->var = $var; 25 | $this->name = \is_string($name) ? new Identifier($name) : $name; 26 | } 27 | 28 | public function getSubNodeNames(): array { 29 | return ['var', 'name']; 30 | } 31 | 32 | public function getType(): string { 33 | return 'Expr_NullsafePropertyFetch'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/PostDec.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $var, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->var = $var; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['var']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_PostDec'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/PostInc.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $var, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->var = $var; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['var']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_PostInc'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/PreDec.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $var, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->var = $var; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['var']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_PreDec'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/PreInc.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $var, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->var = $var; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['var']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_PreInc'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Print_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_Print'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/PropertyFetch.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 21 | */ 22 | public function __construct(Expr $var, $name, array $attributes = []) { 23 | $this->attributes = $attributes; 24 | $this->var = $var; 25 | $this->name = \is_string($name) ? new Identifier($name) : $name; 26 | } 27 | 28 | public function getSubNodeNames(): array { 29 | return ['var', 'name']; 30 | } 31 | 32 | public function getType(): string { 33 | return 'Expr_PropertyFetch'; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/ShellExec.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 17 | */ 18 | public function __construct(array $parts, array $attributes = []) { 19 | $this->attributes = $attributes; 20 | $this->parts = $parts; 21 | } 22 | 23 | public function getSubNodeNames(): array { 24 | return ['parts']; 25 | } 26 | 27 | public function getType(): string { 28 | return 'Expr_ShellExec'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/StaticCall.php: -------------------------------------------------------------------------------- 1 | Arguments */ 17 | public array $args; 18 | 19 | /** 20 | * Constructs a static method call node. 21 | * 22 | * @param Node\Name|Expr $class Class name 23 | * @param string|Identifier|Expr $name Method name 24 | * @param array $args Arguments 25 | * @param array $attributes Additional attributes 26 | */ 27 | public function __construct(Node $class, $name, array $args = [], array $attributes = []) { 28 | $this->attributes = $attributes; 29 | $this->class = $class; 30 | $this->name = \is_string($name) ? new Identifier($name) : $name; 31 | $this->args = $args; 32 | } 33 | 34 | public function getSubNodeNames(): array { 35 | return ['class', 'name', 'args']; 36 | } 37 | 38 | public function getType(): string { 39 | return 'Expr_StaticCall'; 40 | } 41 | 42 | public function getRawArgs(): array { 43 | return $this->args; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/StaticPropertyFetch.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 22 | */ 23 | public function __construct(Node $class, $name, array $attributes = []) { 24 | $this->attributes = $attributes; 25 | $this->class = $class; 26 | $this->name = \is_string($name) ? new VarLikeIdentifier($name) : $name; 27 | } 28 | 29 | public function getSubNodeNames(): array { 30 | return ['class', 'name']; 31 | } 32 | 33 | public function getType(): string { 34 | return 'Expr_StaticPropertyFetch'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Ternary.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 22 | */ 23 | public function __construct(Expr $cond, ?Expr $if, Expr $else, array $attributes = []) { 24 | $this->attributes = $attributes; 25 | $this->cond = $cond; 26 | $this->if = $if; 27 | $this->else = $else; 28 | } 29 | 30 | public function getSubNodeNames(): array { 31 | return ['cond', 'if', 'else']; 32 | } 33 | 34 | public function getType(): string { 35 | return 'Expr_Ternary'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Throw_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Node\Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_Throw'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/UnaryMinus.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_UnaryMinus'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/UnaryPlus.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_UnaryPlus'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Variable.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct($name, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->name = $name; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['name']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_Variable'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/YieldFrom.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Expr $expr, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Expr_YieldFrom'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Expr/Yield_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(?Expr $value = null, ?Expr $key = null, array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->key = $key; 23 | $this->value = $value; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['key', 'value']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Expr_Yield'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/FunctionLike.php: -------------------------------------------------------------------------------- 1 | */ 18 | private static array $specialClassNames = [ 19 | 'self' => true, 20 | 'parent' => true, 21 | 'static' => true, 22 | ]; 23 | 24 | /** 25 | * Constructs an identifier node. 26 | * 27 | * @param string $name Identifier as string 28 | * @param array $attributes Additional attributes 29 | */ 30 | public function __construct(string $name, array $attributes = []) { 31 | if ($name === '') { 32 | throw new \InvalidArgumentException('Identifier name cannot be empty'); 33 | } 34 | 35 | $this->attributes = $attributes; 36 | $this->name = $name; 37 | } 38 | 39 | public function getSubNodeNames(): array { 40 | return ['name']; 41 | } 42 | 43 | /** 44 | * Get identifier as string. 45 | * 46 | * @psalm-return non-empty-string 47 | * @return string Identifier as string. 48 | */ 49 | public function toString(): string { 50 | return $this->name; 51 | } 52 | 53 | /** 54 | * Get lowercased identifier as string. 55 | * 56 | * @psalm-return non-empty-string&lowercase-string 57 | * @return string Lowercased identifier as string 58 | */ 59 | public function toLowerString(): string { 60 | return strtolower($this->name); 61 | } 62 | 63 | /** 64 | * Checks whether the identifier is a special class name (self, parent or static). 65 | * 66 | * @return bool Whether identifier is a special class name 67 | */ 68 | public function isSpecialClassName(): bool { 69 | return isset(self::$specialClassNames[strtolower($this->name)]); 70 | } 71 | 72 | /** 73 | * Get identifier as string. 74 | * 75 | * @psalm-return non-empty-string 76 | * @return string Identifier as string 77 | */ 78 | public function __toString(): string { 79 | return $this->name; 80 | } 81 | 82 | public function getType(): string { 83 | return 'Identifier'; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/InterpolatedStringPart.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(string $value, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->value = $value; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['value']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'InterpolatedStringPart'; 28 | } 29 | } 30 | 31 | // @deprecated compatibility alias 32 | class_alias(InterpolatedStringPart::class, Scalar\EncapsedStringPart::class); 33 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/IntersectionType.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 14 | */ 15 | public function __construct(array $types, array $attributes = []) { 16 | $this->attributes = $attributes; 17 | $this->types = $types; 18 | } 19 | 20 | public function getSubNodeNames(): array { 21 | return ['types']; 22 | } 23 | 24 | public function getType(): string { 25 | return 'IntersectionType'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/MatchArm.php: -------------------------------------------------------------------------------- 1 | */ 10 | public ?array $conds; 11 | public Expr $body; 12 | 13 | /** 14 | * @param null|list $conds 15 | */ 16 | public function __construct(?array $conds, Node\Expr $body, array $attributes = []) { 17 | $this->conds = $conds; 18 | $this->body = $body; 19 | $this->attributes = $attributes; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['conds', 'body']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'MatchArm'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Name/FullyQualified.php: -------------------------------------------------------------------------------- 1 | toString(); 44 | } 45 | 46 | public function getType(): string { 47 | return 'Name_FullyQualified'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Name/Relative.php: -------------------------------------------------------------------------------- 1 | toString(); 44 | } 45 | 46 | public function getType(): string { 47 | return 'Name_Relative'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/NullableType.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(Node $type, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->type = $type; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['type']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'NullableType'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/PropertyItem.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 20 | */ 21 | public function __construct($name, ?Node\Expr $default = null, array $attributes = []) { 22 | $this->attributes = $attributes; 23 | $this->name = \is_string($name) ? new Node\VarLikeIdentifier($name) : $name; 24 | $this->default = $default; 25 | } 26 | 27 | public function getSubNodeNames(): array { 28 | return ['name', 'default']; 29 | } 30 | 31 | public function getType(): string { 32 | return 'PropertyItem'; 33 | } 34 | } 35 | 36 | // @deprecated compatibility alias 37 | class_alias(PropertyItem::class, Stmt\PropertyProperty::class); 38 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Scalar.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(float $value, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->value = $value; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['value']; 24 | } 25 | 26 | /** 27 | * @param mixed[] $attributes 28 | */ 29 | public static function fromString(string $str, array $attributes = []): Float_ { 30 | $attributes['rawValue'] = $str; 31 | $float = self::parse($str); 32 | 33 | return new Float_($float, $attributes); 34 | } 35 | 36 | /** 37 | * @internal 38 | * 39 | * Parses a DNUMBER token like PHP would. 40 | * 41 | * @param string $str A string number 42 | * 43 | * @return float The parsed number 44 | */ 45 | public static function parse(string $str): float { 46 | $str = str_replace('_', '', $str); 47 | 48 | // Check whether this is one of the special integer notations. 49 | if ('0' === $str[0]) { 50 | // hex 51 | if ('x' === $str[1] || 'X' === $str[1]) { 52 | return hexdec($str); 53 | } 54 | 55 | // bin 56 | if ('b' === $str[1] || 'B' === $str[1]) { 57 | return bindec($str); 58 | } 59 | 60 | // oct, but only if the string does not contain any of '.eE'. 61 | if (false === strpbrk($str, '.eE')) { 62 | // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit 63 | // (8 or 9) so that only the digits before that are used. 64 | return octdec(substr($str, 0, strcspn($str, '89'))); 65 | } 66 | } 67 | 68 | // dec 69 | return (float) $str; 70 | } 71 | 72 | public function getType(): string { 73 | return 'Scalar_Float'; 74 | } 75 | } 76 | 77 | // @deprecated compatibility alias 78 | class_alias(Float_::class, DNumber::class); 79 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Scalar/Int_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 23 | */ 24 | public function __construct(int $value, array $attributes = []) { 25 | $this->attributes = $attributes; 26 | $this->value = $value; 27 | } 28 | 29 | public function getSubNodeNames(): array { 30 | return ['value']; 31 | } 32 | 33 | /** 34 | * Constructs an Int node from a string number literal. 35 | * 36 | * @param string $str String number literal (decimal, octal, hex or binary) 37 | * @param array $attributes Additional attributes 38 | * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) 39 | * 40 | * @return Int_ The constructed LNumber, including kind attribute 41 | */ 42 | public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false): Int_ { 43 | $attributes['rawValue'] = $str; 44 | 45 | $str = str_replace('_', '', $str); 46 | 47 | if ('0' !== $str[0] || '0' === $str) { 48 | $attributes['kind'] = Int_::KIND_DEC; 49 | return new Int_((int) $str, $attributes); 50 | } 51 | 52 | if ('x' === $str[1] || 'X' === $str[1]) { 53 | $attributes['kind'] = Int_::KIND_HEX; 54 | return new Int_(hexdec($str), $attributes); 55 | } 56 | 57 | if ('b' === $str[1] || 'B' === $str[1]) { 58 | $attributes['kind'] = Int_::KIND_BIN; 59 | return new Int_(bindec($str), $attributes); 60 | } 61 | 62 | if (!$allowInvalidOctal && strpbrk($str, '89')) { 63 | throw new Error('Invalid numeric literal', $attributes); 64 | } 65 | 66 | // Strip optional explicit octal prefix. 67 | if ('o' === $str[1] || 'O' === $str[1]) { 68 | $str = substr($str, 2); 69 | } 70 | 71 | // use intval instead of octdec to get proper cutting behavior with malformed numbers 72 | $attributes['kind'] = Int_::KIND_OCT; 73 | return new Int_(intval($str, 8), $attributes); 74 | } 75 | 76 | public function getType(): string { 77 | return 'Scalar_Int'; 78 | } 79 | } 80 | 81 | // @deprecated compatibility alias 82 | class_alias(Int_::class, LNumber::class); 83 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Scalar/InterpolatedString.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 18 | */ 19 | public function __construct(array $parts, array $attributes = []) { 20 | $this->attributes = $attributes; 21 | $this->parts = $parts; 22 | } 23 | 24 | public function getSubNodeNames(): array { 25 | return ['parts']; 26 | } 27 | 28 | public function getType(): string { 29 | return 'Scalar_InterpolatedString'; 30 | } 31 | } 32 | 33 | // @deprecated compatibility alias 34 | class_alias(InterpolatedString::class, Encapsed::class); 35 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Scalar/LNumber.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 12 | */ 13 | public function __construct(array $attributes = []) { 14 | $this->attributes = $attributes; 15 | } 16 | 17 | public function getSubNodeNames(): array { 18 | return []; 19 | } 20 | 21 | /** 22 | * Get name of magic constant. 23 | * 24 | * @return string Name of magic constant 25 | */ 26 | abstract public function getName(): string; 27 | } 28 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Scalar/MagicConst/Class_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 20 | */ 21 | public function __construct( 22 | Expr\Variable $var, ?Node\Expr $default = null, array $attributes = [] 23 | ) { 24 | $this->attributes = $attributes; 25 | $this->var = $var; 26 | $this->default = $default; 27 | } 28 | 29 | public function getSubNodeNames(): array { 30 | return ['var', 'default']; 31 | } 32 | 33 | public function getType(): string { 34 | return 'StaticVar'; 35 | } 36 | } 37 | 38 | // @deprecated compatibility alias 39 | class_alias(StaticVar::class, Stmt\StaticVar::class); 40 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(array $stmts, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->stmts = $stmts; 20 | } 21 | 22 | public function getType(): string { 23 | return 'Stmt_Block'; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['stmts']; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Break_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(?Node\Expr $num = null, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->num = $num; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['num']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Stmt_Break'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Case_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(?Node\Expr $cond, array $stmts = [], array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->cond = $cond; 23 | $this->stmts = $stmts; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['cond', 'stmts']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Stmt_Case'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Catch_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 23 | */ 24 | public function __construct( 25 | array $types, ?Expr\Variable $var = null, array $stmts = [], array $attributes = [] 26 | ) { 27 | $this->attributes = $attributes; 28 | $this->types = $types; 29 | $this->var = $var; 30 | $this->stmts = $stmts; 31 | } 32 | 33 | public function getSubNodeNames(): array { 34 | return ['types', 'var', 'stmts']; 35 | } 36 | 37 | public function getType(): string { 38 | return 'Stmt_Catch'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/ClassConst.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 24 | * @param list $attrGroups PHP attribute groups 25 | * @param null|Node\Identifier|Node\Name|Node\ComplexType $type Type declaration 26 | */ 27 | public function __construct( 28 | array $consts, 29 | int $flags = 0, 30 | array $attributes = [], 31 | array $attrGroups = [], 32 | ?Node $type = null 33 | ) { 34 | $this->attributes = $attributes; 35 | $this->flags = $flags; 36 | $this->consts = $consts; 37 | $this->attrGroups = $attrGroups; 38 | $this->type = $type; 39 | } 40 | 41 | public function getSubNodeNames(): array { 42 | return ['attrGroups', 'flags', 'type', 'consts']; 43 | } 44 | 45 | /** 46 | * Whether constant is explicitly or implicitly public. 47 | */ 48 | public function isPublic(): bool { 49 | return ($this->flags & Modifiers::PUBLIC) !== 0 50 | || ($this->flags & Modifiers::VISIBILITY_MASK) === 0; 51 | } 52 | 53 | /** 54 | * Whether constant is protected. 55 | */ 56 | public function isProtected(): bool { 57 | return (bool) ($this->flags & Modifiers::PROTECTED); 58 | } 59 | 60 | /** 61 | * Whether constant is private. 62 | */ 63 | public function isPrivate(): bool { 64 | return (bool) ($this->flags & Modifiers::PRIVATE); 65 | } 66 | 67 | /** 68 | * Whether constant is final. 69 | */ 70 | public function isFinal(): bool { 71 | return (bool) ($this->flags & Modifiers::FINAL); 72 | } 73 | 74 | public function getType(): string { 75 | return 'Stmt_ClassConst'; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Const_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 18 | * @param list $attrGroups PHP attribute groups 19 | */ 20 | public function __construct( 21 | array $consts, 22 | array $attributes = [], 23 | array $attrGroups = [] 24 | ) { 25 | $this->attributes = $attributes; 26 | $this->attrGroups = $attrGroups; 27 | $this->consts = $consts; 28 | } 29 | 30 | public function getSubNodeNames(): array { 31 | return ['attrGroups', 'consts']; 32 | } 33 | 34 | public function getType(): string { 35 | return 'Stmt_Const'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Continue_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(?Node\Expr $num = null, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->num = $num; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['num']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Stmt_Continue'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/DeclareDeclare.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 20 | */ 21 | public function __construct(array $declares, ?array $stmts = null, array $attributes = []) { 22 | $this->attributes = $attributes; 23 | $this->declares = $declares; 24 | $this->stmts = $stmts; 25 | } 26 | 27 | public function getSubNodeNames(): array { 28 | return ['declares', 'stmts']; 29 | } 30 | 31 | public function getType(): string { 32 | return 'Stmt_Declare'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Do_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->cond = $cond; 23 | $this->stmts = $stmts; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['stmts', 'cond']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Stmt_Do'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Echo_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(array $exprs, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->exprs = $exprs; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['exprs']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Stmt_Echo'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/ElseIf_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->cond = $cond; 23 | $this->stmts = $stmts; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['cond', 'stmts']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Stmt_ElseIf'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Else_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(array $stmts = [], array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->stmts = $stmts; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['stmts']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Stmt_Else'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/EnumCase.php: -------------------------------------------------------------------------------- 1 | $attrGroups PHP attribute groups 20 | * @param array $attributes Additional attributes 21 | */ 22 | public function __construct($name, ?Node\Expr $expr = null, array $attrGroups = [], array $attributes = []) { 23 | parent::__construct($attributes); 24 | $this->name = \is_string($name) ? new Node\Identifier($name) : $name; 25 | $this->expr = $expr; 26 | $this->attrGroups = $attrGroups; 27 | } 28 | 29 | public function getSubNodeNames(): array { 30 | return ['attrGroups', 'name', 'expr']; 31 | } 32 | 33 | public function getType(): string { 34 | return 'Stmt_EnumCase'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Enum_.php: -------------------------------------------------------------------------------- 1 | null : Scalar type 22 | * 'implements' => array() : Names of implemented interfaces 23 | * 'stmts' => array() : Statements 24 | * 'attrGroups' => array() : PHP attribute groups 25 | * @param array $attributes Additional attributes 26 | */ 27 | public function __construct($name, array $subNodes = [], array $attributes = []) { 28 | $this->name = \is_string($name) ? new Node\Identifier($name) : $name; 29 | $this->scalarType = $subNodes['scalarType'] ?? null; 30 | $this->implements = $subNodes['implements'] ?? []; 31 | $this->stmts = $subNodes['stmts'] ?? []; 32 | $this->attrGroups = $subNodes['attrGroups'] ?? []; 33 | 34 | parent::__construct($attributes); 35 | } 36 | 37 | public function getSubNodeNames(): array { 38 | return ['attrGroups', 'name', 'scalarType', 'implements', 'stmts']; 39 | } 40 | 41 | public function getType(): string { 42 | return 'Stmt_Enum'; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Expression.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(Node\Expr $expr, array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->expr = $expr; 23 | } 24 | 25 | public function getSubNodeNames(): array { 26 | return ['expr']; 27 | } 28 | 29 | public function getType(): string { 30 | return 'Stmt_Expression'; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Finally_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(array $stmts = [], array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->stmts = $stmts; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['stmts']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Stmt_Finally'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/For_.php: -------------------------------------------------------------------------------- 1 | array(): Init expressions 27 | * 'cond' => array(): Loop conditions 28 | * 'loop' => array(): Loop expressions 29 | * 'stmts' => array(): Statements 30 | * @param array $attributes Additional attributes 31 | */ 32 | public function __construct(array $subNodes = [], array $attributes = []) { 33 | $this->attributes = $attributes; 34 | $this->init = $subNodes['init'] ?? []; 35 | $this->cond = $subNodes['cond'] ?? []; 36 | $this->loop = $subNodes['loop'] ?? []; 37 | $this->stmts = $subNodes['stmts'] ?? []; 38 | } 39 | 40 | public function getSubNodeNames(): array { 41 | return ['init', 'cond', 'loop', 'stmts']; 42 | } 43 | 44 | public function getType(): string { 45 | return 'Stmt_For'; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Foreach_.php: -------------------------------------------------------------------------------- 1 | null : Variable to assign key to 30 | * 'byRef' => false : Whether to assign value by reference 31 | * 'stmts' => array(): Statements 32 | * @param array $attributes Additional attributes 33 | */ 34 | public function __construct(Node\Expr $expr, Node\Expr $valueVar, array $subNodes = [], array $attributes = []) { 35 | $this->attributes = $attributes; 36 | $this->expr = $expr; 37 | $this->keyVar = $subNodes['keyVar'] ?? null; 38 | $this->byRef = $subNodes['byRef'] ?? false; 39 | $this->valueVar = $valueVar; 40 | $this->stmts = $subNodes['stmts'] ?? []; 41 | } 42 | 43 | public function getSubNodeNames(): array { 44 | return ['expr', 'keyVar', 'byRef', 'valueVar', 'stmts']; 45 | } 46 | 47 | public function getType(): string { 48 | return 'Stmt_Foreach'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Global_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(array $vars, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->vars = $vars; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['vars']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Stmt_Global'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Goto_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 17 | */ 18 | public function __construct($name, array $attributes = []) { 19 | $this->attributes = $attributes; 20 | $this->name = \is_string($name) ? new Identifier($name) : $name; 21 | } 22 | 23 | public function getSubNodeNames(): array { 24 | return ['name']; 25 | } 26 | 27 | public function getType(): string { 28 | return 'Stmt_Goto'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/GroupUse.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 26 | */ 27 | public function __construct(Name $prefix, array $uses, int $type = Use_::TYPE_NORMAL, array $attributes = []) { 28 | $this->attributes = $attributes; 29 | $this->type = $type; 30 | $this->prefix = $prefix; 31 | $this->uses = $uses; 32 | } 33 | 34 | public function getSubNodeNames(): array { 35 | return ['type', 'prefix', 'uses']; 36 | } 37 | 38 | public function getType(): string { 39 | return 'Stmt_GroupUse'; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/HaltCompiler.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(string $remaining, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->remaining = $remaining; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['remaining']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Stmt_HaltCompiler'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/If_.php: -------------------------------------------------------------------------------- 1 | array(): Statements 27 | * 'elseifs' => array(): Elseif clauses 28 | * 'else' => null : Else clause 29 | * @param array $attributes Additional attributes 30 | */ 31 | public function __construct(Node\Expr $cond, array $subNodes = [], array $attributes = []) { 32 | $this->attributes = $attributes; 33 | $this->cond = $cond; 34 | $this->stmts = $subNodes['stmts'] ?? []; 35 | $this->elseifs = $subNodes['elseifs'] ?? []; 36 | $this->else = $subNodes['else'] ?? null; 37 | } 38 | 39 | public function getSubNodeNames(): array { 40 | return ['cond', 'stmts', 'elseifs', 'else']; 41 | } 42 | 43 | public function getType(): string { 44 | return 'Stmt_If'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/InlineHTML.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(string $value, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->value = $value; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['value']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Stmt_InlineHTML'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Interface_.php: -------------------------------------------------------------------------------- 1 | array(): Name of extended interfaces 21 | * 'stmts' => array(): Statements 22 | * 'attrGroups' => array(): PHP attribute groups 23 | * @param array $attributes Additional attributes 24 | */ 25 | public function __construct($name, array $subNodes = [], array $attributes = []) { 26 | $this->attributes = $attributes; 27 | $this->name = \is_string($name) ? new Node\Identifier($name) : $name; 28 | $this->extends = $subNodes['extends'] ?? []; 29 | $this->stmts = $subNodes['stmts'] ?? []; 30 | $this->attrGroups = $subNodes['attrGroups'] ?? []; 31 | } 32 | 33 | public function getSubNodeNames(): array { 34 | return ['attrGroups', 'name', 'extends', 'stmts']; 35 | } 36 | 37 | public function getType(): string { 38 | return 'Stmt_Interface'; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Label.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 17 | */ 18 | public function __construct($name, array $attributes = []) { 19 | $this->attributes = $attributes; 20 | $this->name = \is_string($name) ? new Identifier($name) : $name; 21 | } 22 | 23 | public function getSubNodeNames(): array { 24 | return ['name']; 25 | } 26 | 27 | public function getType(): string { 28 | return 'Stmt_Label'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Namespace_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 23 | */ 24 | public function __construct(?Node\Name $name = null, ?array $stmts = [], array $attributes = []) { 25 | $this->attributes = $attributes; 26 | $this->name = $name; 27 | $this->stmts = $stmts; 28 | } 29 | 30 | public function getSubNodeNames(): array { 31 | return ['name', 'stmts']; 32 | } 33 | 34 | public function getType(): string { 35 | return 'Stmt_Namespace'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Nop.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(?Node\Expr $expr = null, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->expr = $expr; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['expr']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Stmt_Return'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/StaticVar.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 17 | */ 18 | public function __construct(array $vars, array $attributes = []) { 19 | $this->attributes = $attributes; 20 | $this->vars = $vars; 21 | } 22 | 23 | public function getSubNodeNames(): array { 24 | return ['vars']; 25 | } 26 | 27 | public function getType(): string { 28 | return 'Stmt_Static'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Switch_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(Node\Expr $cond, array $cases, array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->cond = $cond; 23 | $this->cases = $cases; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['cond', 'cases']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Stmt_Switch'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/TraitUse.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(array $traits, array $adaptations = [], array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->traits = $traits; 23 | $this->adaptations = $adaptations; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['traits', 'adaptations']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Stmt_TraitUse'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/TraitUseAdaptation.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 21 | */ 22 | public function __construct(?Node\Name $trait, $method, ?int $newModifier, $newName, array $attributes = []) { 23 | $this->attributes = $attributes; 24 | $this->trait = $trait; 25 | $this->method = \is_string($method) ? new Node\Identifier($method) : $method; 26 | $this->newModifier = $newModifier; 27 | $this->newName = \is_string($newName) ? new Node\Identifier($newName) : $newName; 28 | } 29 | 30 | public function getSubNodeNames(): array { 31 | return ['trait', 'method', 'newModifier', 'newName']; 32 | } 33 | 34 | public function getType(): string { 35 | return 'Stmt_TraitUseAdaptation_Alias'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/TraitUseAdaptation/Precedence.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 18 | */ 19 | public function __construct(Node\Name $trait, $method, array $insteadof, array $attributes = []) { 20 | $this->attributes = $attributes; 21 | $this->trait = $trait; 22 | $this->method = \is_string($method) ? new Node\Identifier($method) : $method; 23 | $this->insteadof = $insteadof; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['trait', 'method', 'insteadof']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Stmt_TraitUseAdaptation_Precedence'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Trait_.php: -------------------------------------------------------------------------------- 1 | array(): Statements 17 | * 'attrGroups' => array(): PHP attribute groups 18 | * @param array $attributes Additional attributes 19 | */ 20 | public function __construct($name, array $subNodes = [], array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->name = \is_string($name) ? new Node\Identifier($name) : $name; 23 | $this->stmts = $subNodes['stmts'] ?? []; 24 | $this->attrGroups = $subNodes['attrGroups'] ?? []; 25 | } 26 | 27 | public function getSubNodeNames(): array { 28 | return ['attrGroups', 'name', 'stmts']; 29 | } 30 | 31 | public function getType(): string { 32 | return 'Stmt_Trait'; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/TryCatch.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 22 | */ 23 | public function __construct(array $stmts, array $catches, ?Finally_ $finally = null, array $attributes = []) { 24 | $this->attributes = $attributes; 25 | $this->stmts = $stmts; 26 | $this->catches = $catches; 27 | $this->finally = $finally; 28 | } 29 | 30 | public function getSubNodeNames(): array { 31 | return ['stmts', 'catches', 'finally']; 32 | } 33 | 34 | public function getType(): string { 35 | return 'Stmt_TryCatch'; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/Unset_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 16 | */ 17 | public function __construct(array $vars, array $attributes = []) { 18 | $this->attributes = $attributes; 19 | $this->vars = $vars; 20 | } 21 | 22 | public function getSubNodeNames(): array { 23 | return ['vars']; 24 | } 25 | 26 | public function getType(): string { 27 | return 'Stmt_Unset'; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/UseUse.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 33 | */ 34 | public function __construct(array $uses, int $type = self::TYPE_NORMAL, array $attributes = []) { 35 | $this->attributes = $attributes; 36 | $this->type = $type; 37 | $this->uses = $uses; 38 | } 39 | 40 | public function getSubNodeNames(): array { 41 | return ['type', 'uses']; 42 | } 43 | 44 | public function getType(): string { 45 | return 'Stmt_Use'; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/Stmt/While_.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 19 | */ 20 | public function __construct(Node\Expr $cond, array $stmts = [], array $attributes = []) { 21 | $this->attributes = $attributes; 22 | $this->cond = $cond; 23 | $this->stmts = $stmts; 24 | } 25 | 26 | public function getSubNodeNames(): array { 27 | return ['cond', 'stmts']; 28 | } 29 | 30 | public function getType(): string { 31 | return 'Stmt_While'; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/UnionType.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 14 | */ 15 | public function __construct(array $types, array $attributes = []) { 16 | $this->attributes = $attributes; 17 | $this->types = $types; 18 | } 19 | 20 | public function getSubNodeNames(): array { 21 | return ['types']; 22 | } 23 | 24 | public function getType(): string { 25 | return 'UnionType'; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/UseItem.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 26 | */ 27 | public function __construct(Node\Name $name, $alias = null, int $type = Use_::TYPE_UNKNOWN, array $attributes = []) { 28 | $this->attributes = $attributes; 29 | $this->type = $type; 30 | $this->name = $name; 31 | $this->alias = \is_string($alias) ? new Identifier($alias) : $alias; 32 | } 33 | 34 | public function getSubNodeNames(): array { 35 | return ['type', 'name', 'alias']; 36 | } 37 | 38 | /** 39 | * Get alias. If not explicitly given this is the last component of the used name. 40 | */ 41 | public function getAlias(): Identifier { 42 | if (null !== $this->alias) { 43 | return $this->alias; 44 | } 45 | 46 | return new Identifier($this->name->getLast()); 47 | } 48 | 49 | public function getType(): string { 50 | return 'UseItem'; 51 | } 52 | } 53 | 54 | // @deprecated compatibility alias 55 | class_alias(UseItem::class, Stmt\UseUse::class); 56 | -------------------------------------------------------------------------------- /lib/PhpParser/Node/VarLikeIdentifier.php: -------------------------------------------------------------------------------- 1 | $attributes Additional attributes 15 | */ 16 | public function __construct(array $attributes = []) { 17 | $this->attributes = $attributes; 18 | } 19 | 20 | public function getType(): string { 21 | return 'VariadicPlaceholder'; 22 | } 23 | 24 | public function getSubNodeNames(): array { 25 | return []; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/PhpParser/NodeTraverserInterface.php: -------------------------------------------------------------------------------- 1 | setAttribute('origNode', $origNode); 17 | return $node; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/PhpParser/NodeVisitor/FindingVisitor.php: -------------------------------------------------------------------------------- 1 | Found nodes */ 16 | protected array $foundNodes; 17 | 18 | public function __construct(callable $filterCallback) { 19 | $this->filterCallback = $filterCallback; 20 | } 21 | 22 | /** 23 | * Get found nodes satisfying the filter callback. 24 | * 25 | * Nodes are returned in pre-order. 26 | * 27 | * @return list Found nodes 28 | */ 29 | public function getFoundNodes(): array { 30 | return $this->foundNodes; 31 | } 32 | 33 | public function beforeTraverse(array $nodes): ?array { 34 | $this->foundNodes = []; 35 | 36 | return null; 37 | } 38 | 39 | public function enterNode(Node $node) { 40 | $filterCallback = $this->filterCallback; 41 | if ($filterCallback($node)) { 42 | $this->foundNodes[] = $node; 43 | } 44 | 45 | return null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/PhpParser/NodeVisitor/FirstFindingVisitor.php: -------------------------------------------------------------------------------- 1 | filterCallback = $filterCallback; 21 | } 22 | 23 | /** 24 | * Get found node satisfying the filter callback. 25 | * 26 | * Returns null if no node satisfies the filter callback. 27 | * 28 | * @return null|Node Found node (or null if not found) 29 | */ 30 | public function getFoundNode(): ?Node { 31 | return $this->foundNode; 32 | } 33 | 34 | public function beforeTraverse(array $nodes): ?array { 35 | $this->foundNode = null; 36 | 37 | return null; 38 | } 39 | 40 | public function enterNode(Node $node) { 41 | $filterCallback = $this->filterCallback; 42 | if ($filterCallback($node)) { 43 | $this->foundNode = $node; 44 | return NodeVisitor::STOP_TRAVERSAL; 45 | } 46 | 47 | return null; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php: -------------------------------------------------------------------------------- 1 | $weakReferences=false on the child node, the parent node can be accessed through 13 | * $node->getAttribute('parent'), the previous 14 | * node can be accessed through $node->getAttribute('previous'), 15 | * and the next node can be accessed through $node->getAttribute('next'). 16 | * 17 | * With $weakReferences=true attribute names are prefixed by "weak_", e.g. "weak_parent". 18 | */ 19 | final class NodeConnectingVisitor extends NodeVisitorAbstract { 20 | /** 21 | * @var Node[] 22 | */ 23 | private array $stack = []; 24 | 25 | /** 26 | * @var ?Node 27 | */ 28 | private $previous; 29 | 30 | private bool $weakReferences; 31 | 32 | public function __construct(bool $weakReferences = false) { 33 | $this->weakReferences = $weakReferences; 34 | } 35 | 36 | public function beforeTraverse(array $nodes) { 37 | $this->stack = []; 38 | $this->previous = null; 39 | } 40 | 41 | public function enterNode(Node $node) { 42 | if (!empty($this->stack)) { 43 | $parent = $this->stack[count($this->stack) - 1]; 44 | if ($this->weakReferences) { 45 | $node->setAttribute('weak_parent', \WeakReference::create($parent)); 46 | } else { 47 | $node->setAttribute('parent', $parent); 48 | } 49 | } 50 | 51 | if ($this->previous !== null) { 52 | if ( 53 | $this->weakReferences 54 | ) { 55 | if ($this->previous->getAttribute('weak_parent') === $node->getAttribute('weak_parent')) { 56 | $node->setAttribute('weak_previous', \WeakReference::create($this->previous)); 57 | $this->previous->setAttribute('weak_next', \WeakReference::create($node)); 58 | } 59 | } elseif ($this->previous->getAttribute('parent') === $node->getAttribute('parent')) { 60 | $node->setAttribute('previous', $this->previous); 61 | $this->previous->setAttribute('next', $node); 62 | } 63 | } 64 | 65 | $this->stack[] = $node; 66 | } 67 | 68 | public function leaveNode(Node $node) { 69 | $this->previous = $node; 70 | 71 | array_pop($this->stack); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php: -------------------------------------------------------------------------------- 1 | $weakReferences=false on the child node, the parent node can be accessed through 15 | * $node->getAttribute('parent'). 16 | * 17 | * With $weakReferences=true the attribute name is "weak_parent" instead. 18 | */ 19 | final class ParentConnectingVisitor extends NodeVisitorAbstract { 20 | /** 21 | * @var Node[] 22 | */ 23 | private array $stack = []; 24 | 25 | private bool $weakReferences; 26 | 27 | public function __construct(bool $weakReferences = false) { 28 | $this->weakReferences = $weakReferences; 29 | } 30 | 31 | public function beforeTraverse(array $nodes) { 32 | $this->stack = []; 33 | } 34 | 35 | public function enterNode(Node $node) { 36 | if (!empty($this->stack)) { 37 | $parent = $this->stack[count($this->stack) - 1]; 38 | if ($this->weakReferences) { 39 | $node->setAttribute('weak_parent', \WeakReference::create($parent)); 40 | } else { 41 | $node->setAttribute('parent', $parent); 42 | } 43 | } 44 | 45 | $this->stack[] = $node; 46 | } 47 | 48 | public function leaveNode(Node $node) { 49 | array_pop($this->stack); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lib/PhpParser/NodeVisitorAbstract.php: -------------------------------------------------------------------------------- 1 | isHostVersion()) { 16 | $lexer = new Lexer(); 17 | } else { 18 | $lexer = new Lexer\Emulative($version); 19 | } 20 | if ($version->id >= 80000) { 21 | return new Php8($lexer, $version); 22 | } 23 | return new Php7($lexer, $version); 24 | } 25 | 26 | /** 27 | * Create a parser targeting the newest version supported by this library. Code for older 28 | * versions will be accepted if there have been no relevant backwards-compatibility breaks in 29 | * PHP. 30 | */ 31 | public function createForNewestSupportedVersion(): Parser { 32 | return $this->createForVersion(PhpVersion::getNewestSupported()); 33 | } 34 | 35 | /** 36 | * Create a parser targeting the host PHP version, that is the PHP version we're currently 37 | * running on. This parser will not use any token emulation. 38 | */ 39 | public function createForHostVersion(): Parser { 40 | return $this->createForVersion(PhpVersion::getHostVersion()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lib/PhpParser/PrettyPrinter.php: -------------------------------------------------------------------------------- 1 | pos + \strlen($this->text); 12 | } 13 | 14 | /** Get 1-based end line number of the token. */ 15 | public function getEndLine(): int { 16 | return $this->line + \substr_count($this->text, "\n"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/PhpParser/compatibility_tokens.php: -------------------------------------------------------------------------------- 1 |