Add more property types

Some of these are not maximally accurate due to lack of union
types.
This commit is contained in:
Nikita Popov
2023-08-17 21:35:48 +02:00
parent 9a68468fda
commit ea77807592
34 changed files with 90 additions and 82 deletions

View File

@@ -22,8 +22,8 @@ class ClassConst implements PhpParser\Builder {
/** @var list<Node\AttributeGroup> */ /** @var list<Node\AttributeGroup> */
protected array $attributeGroups = []; protected array $attributeGroups = [];
/** @var Identifier|Node\Name|Node\ComplexType */ /** @var Identifier|Node\Name|Node\ComplexType|null */
protected $type; protected ?Node $type = null;
/** /**
* Creates a class constant builder * Creates a class constant builder

View File

@@ -14,7 +14,7 @@ class EnumCase implements PhpParser\Builder {
/** @var Identifier|string */ /** @var Identifier|string */
protected $name; protected $name;
/** @var ?Node\Expr */ /** @var ?Node\Expr */
protected $value = null; protected ?Node\Expr $value = null;
/** @var array<string, mixed> */ /** @var array<string, mixed> */
protected array $attributes = []; protected array $attributes = [];

View File

@@ -12,7 +12,7 @@ abstract class FunctionLike extends Declaration {
protected array $params = []; protected array $params = [];
/** @var Node\Identifier|Node\Name|Node\ComplexType|null */ /** @var Node\Identifier|Node\Name|Node\ComplexType|null */
protected $returnType = null; protected ?Node $returnType = null;
/** /**
* Make the function return by reference. * Make the function return by reference.

View File

@@ -13,7 +13,7 @@ class Param implements PhpParser\Builder {
/** @var Node\Expr|null */ /** @var Node\Expr|null */
protected ?Node\Expr $default = null; protected ?Node\Expr $default = null;
/** @var Node\Identifier|Node\Name|Node\ComplexType|null */ /** @var Node\Identifier|Node\Name|Node\ComplexType|null */
protected $type = null; protected ?Node $type = null;
/** @var bool */ /** @var bool */
protected bool $byRef = false; protected bool $byRef = false;
/** @var int */ /** @var int */

View File

@@ -21,7 +21,7 @@ class Property implements PhpParser\Builder {
/** @var array<string, mixed> */ /** @var array<string, mixed> */
protected array $attributes = []; protected array $attributes = [];
/** @var null|Identifier|Name|ComplexType */ /** @var null|Identifier|Name|ComplexType */
protected $type; protected ?Node $type = null;
/** @var list<Node\AttributeGroup> */ /** @var list<Node\AttributeGroup> */
protected array $attributeGroups = []; protected array $attributeGroups = [];

View File

@@ -21,7 +21,7 @@ class PrintableNewAnonClassNode extends Expr {
/** @var int Modifiers */ /** @var int Modifiers */
public int $flags; public int $flags;
/** @var (Node\Arg|Node\VariadicPlaceholder)[] Arguments */ /** @var (Node\Arg|Node\VariadicPlaceholder)[] Arguments */
public $args; public array $args;
/** @var null|Node\Name Name of extended class */ /** @var null|Node\Name Name of extended class */
public ?Node\Name $extends; public ?Node\Name $extends;
/** @var Node\Name[] Names of implemented interfaces */ /** @var Node\Name[] Names of implemented interfaces */

View File

@@ -17,7 +17,7 @@ class ArrowFunction extends Expr implements FunctionLike {
public array $params = []; public array $params = [];
/** @var null|Node\Identifier|Node\Name|Node\ComplexType */ /** @var null|Node\Identifier|Node\Name|Node\ComplexType */
public $returnType; public ?Node $returnType;
/** @var Expr */ /** @var Expr */
public Expr $expr; public Expr $expr;

View File

@@ -2,15 +2,16 @@
namespace PhpParser\Node\Expr; namespace PhpParser\Node\Expr;
use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
use PhpParser\Node\Name; use PhpParser\Node\Name;
class ClassConstFetch extends Expr { class ClassConstFetch extends Expr {
/** @var Name|Expr Class name */ /** @var Name|Expr Class name */
public $class; public Node $class;
/** @var Identifier|Expr|Error Constant name */ /** @var Identifier|Expr|Error Constant name */
public $name; public Node $name;
/** /**
* Constructs a class const fetch node. * Constructs a class const fetch node.
@@ -19,7 +20,7 @@ class ClassConstFetch extends Expr {
* @param string|Identifier|Expr|Error $name Constant name * @param string|Identifier|Expr|Error $name Constant name
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
*/ */
public function __construct($class, $name, array $attributes = []) { public function __construct(Node $class, $name, array $attributes = []) {
$this->attributes = $attributes; $this->attributes = $attributes;
$this->class = $class; $this->class = $class;
$this->name = \is_string($name) ? new Identifier($name) : $name; $this->name = \is_string($name) ? new Identifier($name) : $name;

View File

@@ -17,7 +17,7 @@ class Closure extends Expr implements FunctionLike {
/** @var ClosureUse[] use()s */ /** @var ClosureUse[] use()s */
public array $uses; public array $uses;
/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */ /** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */
public $returnType; public ?Node $returnType;
/** @var Node\Stmt[] Statements */ /** @var Node\Stmt[] Statements */
public array $stmts; public array $stmts;
/** @var Node\AttributeGroup[] PHP attribute groups */ /** @var Node\AttributeGroup[] PHP attribute groups */

View File

@@ -7,18 +7,18 @@ use PhpParser\Node\Expr;
class FuncCall extends CallLike { class FuncCall extends CallLike {
/** @var Node\Name|Expr Function name */ /** @var Node\Name|Expr Function name */
public $name; public Node $name;
/** @var array<Node\Arg|Node\VariadicPlaceholder> Arguments */ /** @var array<Node\Arg|Node\VariadicPlaceholder> Arguments */
public $args; public array $args;
/** /**
* Constructs a function call node. * Constructs a function call node.
* *
* @param Node\Name|Expr $name Function name * @param Node\Name|Expr $name Function name
* @param array<Node\Arg|Node\VariadicPlaceholder> $args Arguments * @param array<Node\Arg|Node\VariadicPlaceholder> $args Arguments
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
*/ */
public function __construct($name, array $args = [], array $attributes = []) { public function __construct(Node $name, array $args = [], array $attributes = []) {
$this->attributes = $attributes; $this->attributes = $attributes;
$this->name = $name; $this->name = $name;
$this->args = $args; $this->args = $args;

View File

@@ -2,6 +2,7 @@
namespace PhpParser\Node\Expr; namespace PhpParser\Node\Expr;
use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Name; use PhpParser\Node\Name;
@@ -9,16 +10,16 @@ class Instanceof_ extends Expr {
/** @var Expr Expression */ /** @var Expr Expression */
public Expr $expr; public Expr $expr;
/** @var Name|Expr Class name */ /** @var Name|Expr Class name */
public $class; public Node $class;
/** /**
* Constructs an instanceof check node. * Constructs an instanceof check node.
* *
* @param Expr $expr Expression * @param Expr $expr Expression
* @param Name|Expr $class Class name * @param Name|Expr $class Class name
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
*/ */
public function __construct(Expr $expr, $class, array $attributes = []) { public function __construct(Expr $expr, Node $class, array $attributes = []) {
$this->attributes = $attributes; $this->attributes = $attributes;
$this->expr = $expr; $this->expr = $expr;
$this->class = $class; $this->class = $class;

View File

@@ -11,7 +11,7 @@ class List_ extends Expr {
public const KIND_ARRAY = 2; // [] syntax public const KIND_ARRAY = 2; // [] syntax
/** @var (ArrayItem|null)[] List of items to assign to */ /** @var (ArrayItem|null)[] List of items to assign to */
public $items; public array $items;
/** /**
* Constructs a list() destructuring node. * Constructs a list() destructuring node.

View File

@@ -2,6 +2,7 @@
namespace PhpParser\Node\Expr; namespace PhpParser\Node\Expr;
use PhpParser\Node;
use PhpParser\Node\Arg; use PhpParser\Node\Arg;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
@@ -11,16 +12,16 @@ class MethodCall extends CallLike {
/** @var Expr Variable holding object */ /** @var Expr Variable holding object */
public Expr $var; public Expr $var;
/** @var Identifier|Expr Method name */ /** @var Identifier|Expr Method name */
public $name; public Node $name;
/** @var array<Arg|VariadicPlaceholder> Arguments */ /** @var array<Arg|VariadicPlaceholder> Arguments */
public $args; public array $args;
/** /**
* Constructs a function call node. * Constructs a function call node.
* *
* @param Expr $var Variable holding object * @param Expr $var Variable holding object
* @param string|Identifier|Expr $name Method name * @param string|Identifier|Expr $name Method name
* @param array<Arg|VariadicPlaceholder> $args Arguments * @param array<Arg|VariadicPlaceholder> $args Arguments
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
*/ */
public function __construct(Expr $var, $name, array $args = [], array $attributes = []) { public function __construct(Expr $var, $name, array $args = [], array $attributes = []) {

View File

@@ -9,18 +9,18 @@ use PhpParser\Node\VariadicPlaceholder;
class New_ extends CallLike { class New_ extends CallLike {
/** @var Node\Name|Expr|Node\Stmt\Class_ Class name */ /** @var Node\Name|Expr|Node\Stmt\Class_ Class name */
public $class; public Node $class;
/** @var array<Arg|VariadicPlaceholder> Arguments */ /** @var array<Arg|VariadicPlaceholder> Arguments */
public $args; public array $args;
/** /**
* Constructs a function call node. * Constructs a function call node.
* *
* @param Node\Name|Expr|Node\Stmt\Class_ $class Class name (or class node for anonymous classes) * @param Node\Name|Expr|Node\Stmt\Class_ $class Class name (or class node for anonymous classes)
* @param array<Arg|VariadicPlaceholder> $args Arguments * @param array<Arg|VariadicPlaceholder> $args Arguments
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
*/ */
public function __construct($class, array $args = [], array $attributes = []) { public function __construct(Node $class, array $args = [], array $attributes = []) {
$this->attributes = $attributes; $this->attributes = $attributes;
$this->class = $class; $this->class = $class;
$this->args = $args; $this->args = $args;

View File

@@ -2,6 +2,7 @@
namespace PhpParser\Node\Expr; namespace PhpParser\Node\Expr;
use PhpParser\Node;
use PhpParser\Node\Arg; use PhpParser\Node\Arg;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
@@ -11,16 +12,16 @@ class NullsafeMethodCall extends CallLike {
/** @var Expr Variable holding object */ /** @var Expr Variable holding object */
public Expr $var; public Expr $var;
/** @var Identifier|Expr Method name */ /** @var Identifier|Expr Method name */
public $name; public Node $name;
/** @var array<Arg|VariadicPlaceholder> Arguments */ /** @var array<Arg|VariadicPlaceholder> Arguments */
public $args; public array $args;
/** /**
* Constructs a nullsafe method call node. * Constructs a nullsafe method call node.
* *
* @param Expr $var Variable holding object * @param Expr $var Variable holding object
* @param string|Identifier|Expr $name Method name * @param string|Identifier|Expr $name Method name
* @param array<Arg|VariadicPlaceholder> $args Arguments * @param array<Arg|VariadicPlaceholder> $args Arguments
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
*/ */
public function __construct(Expr $var, $name, array $args = [], array $attributes = []) { public function __construct(Expr $var, $name, array $args = [], array $attributes = []) {

View File

@@ -2,6 +2,7 @@
namespace PhpParser\Node\Expr; namespace PhpParser\Node\Expr;
use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
@@ -9,13 +10,13 @@ class NullsafePropertyFetch extends Expr {
/** @var Expr Variable holding object */ /** @var Expr Variable holding object */
public Expr $var; public Expr $var;
/** @var Identifier|Expr Property name */ /** @var Identifier|Expr Property name */
public $name; public Node $name;
/** /**
* Constructs a nullsafe property fetch node. * Constructs a nullsafe property fetch node.
* *
* @param Expr $var Variable holding object * @param Expr $var Variable holding object
* @param string|Identifier|Expr $name Property name * @param string|Identifier|Expr $name Property name
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
*/ */
public function __construct(Expr $var, $name, array $attributes = []) { public function __construct(Expr $var, $name, array $attributes = []) {

View File

@@ -2,6 +2,7 @@
namespace PhpParser\Node\Expr; namespace PhpParser\Node\Expr;
use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
@@ -9,13 +10,13 @@ class PropertyFetch extends Expr {
/** @var Expr Variable holding object */ /** @var Expr Variable holding object */
public Expr $var; public Expr $var;
/** @var Identifier|Expr Property name */ /** @var Identifier|Expr Property name */
public $name; public Node $name;
/** /**
* Constructs a function call node. * Constructs a function call node.
* *
* @param Expr $var Variable holding object * @param Expr $var Variable holding object
* @param string|Identifier|Expr $name Property name * @param string|Identifier|Expr $name Property name
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
*/ */
public function __construct(Expr $var, $name, array $attributes = []) { public function __construct(Expr $var, $name, array $attributes = []) {

View File

@@ -7,7 +7,7 @@ use PhpParser\Node\InterpolatedStringPart;
class ShellExec extends Expr { class ShellExec extends Expr {
/** @var (Expr|InterpolatedStringPart)[] Interpolated string array */ /** @var (Expr|InterpolatedStringPart)[] Interpolated string array */
public $parts; public array $parts;
/** /**
* Constructs a shell exec (backtick) node. * Constructs a shell exec (backtick) node.

View File

@@ -10,21 +10,21 @@ use PhpParser\Node\VariadicPlaceholder;
class StaticCall extends CallLike { class StaticCall extends CallLike {
/** @var Node\Name|Expr Class name */ /** @var Node\Name|Expr Class name */
public $class; public Node $class;
/** @var Identifier|Expr Method name */ /** @var Identifier|Expr Method name */
public $name; public Node $name;
/** @var array<Arg|VariadicPlaceholder> Arguments */ /** @var array<Arg|VariadicPlaceholder> Arguments */
public $args; public array $args;
/** /**
* Constructs a static method call node. * Constructs a static method call node.
* *
* @param Node\Name|Expr $class Class name * @param Node\Name|Expr $class Class name
* @param string|Identifier|Expr $name Method name * @param string|Identifier|Expr $name Method name
* @param array<Arg|VariadicPlaceholder> $args Arguments * @param array<Arg|VariadicPlaceholder> $args Arguments
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
*/ */
public function __construct($class, $name, array $args = [], array $attributes = []) { public function __construct(Node $class, $name, array $args = [], array $attributes = []) {
$this->attributes = $attributes; $this->attributes = $attributes;
$this->class = $class; $this->class = $class;
$this->name = \is_string($name) ? new Identifier($name) : $name; $this->name = \is_string($name) ? new Identifier($name) : $name;

View File

@@ -2,24 +2,25 @@
namespace PhpParser\Node\Expr; namespace PhpParser\Node\Expr;
use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Name; use PhpParser\Node\Name;
use PhpParser\Node\VarLikeIdentifier; use PhpParser\Node\VarLikeIdentifier;
class StaticPropertyFetch extends Expr { class StaticPropertyFetch extends Expr {
/** @var Name|Expr Class name */ /** @var Name|Expr Class name */
public $class; public Node $class;
/** @var VarLikeIdentifier|Expr Property name */ /** @var VarLikeIdentifier|Expr Property name */
public $name; public Node $name;
/** /**
* Constructs a static property fetch node. * Constructs a static property fetch node.
* *
* @param Name|Expr $class Class name * @param Name|Expr $class Class name
* @param string|VarLikeIdentifier|Expr $name Property name * @param string|VarLikeIdentifier|Expr $name Property name
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
*/ */
public function __construct($class, $name, array $attributes = []) { public function __construct(Node $class, $name, array $attributes = []) {
$this->attributes = $attributes; $this->attributes = $attributes;
$this->class = $class; $this->class = $class;
$this->name = \is_string($name) ? new VarLikeIdentifier($name) : $name; $this->name = \is_string($name) ? new VarLikeIdentifier($name) : $name;

View File

@@ -4,7 +4,7 @@ namespace PhpParser\Node;
class IntersectionType extends ComplexType { class IntersectionType extends ComplexType {
/** @var (Identifier|Name)[] Types */ /** @var (Identifier|Name)[] Types */
public $types; public array $types;
/** /**
* Constructs an intersection type. * Constructs an intersection type.

View File

@@ -6,7 +6,7 @@ use PhpParser\Node;
class NullableType extends ComplexType { class NullableType extends ComplexType {
/** @var Identifier|Name Type */ /** @var Identifier|Name Type */
public $type; public Node $type;
/** /**
* Constructs a nullable type (wrapping another type). * Constructs a nullable type (wrapping another type).

View File

@@ -8,13 +8,13 @@ use PhpParser\NodeAbstract;
class Param extends NodeAbstract { class Param extends NodeAbstract {
/** @var null|Identifier|Name|ComplexType Type declaration */ /** @var null|Identifier|Name|ComplexType Type declaration */
public $type; public ?Node $type;
/** @var bool Whether parameter is passed by reference */ /** @var bool Whether parameter is passed by reference */
public bool $byRef; public bool $byRef;
/** @var bool Whether this is a variadic argument */ /** @var bool Whether this is a variadic argument */
public bool $variadic; public bool $variadic;
/** @var Expr\Variable|Expr\Error Parameter variable */ /** @var Expr\Variable|Expr\Error Parameter variable */
public $var; public Expr $var;
/** @var null|Expr Default value */ /** @var null|Expr Default value */
public ?Expr $default; public ?Expr $default;
/** @var int */ /** @var int */
@@ -25,17 +25,17 @@ class Param extends NodeAbstract {
/** /**
* Constructs a parameter node. * Constructs a parameter node.
* *
* @param Expr\Variable|Expr\Error $var Parameter variable * @param Expr\Variable|Expr\Error $var Parameter variable
* @param null|Expr $default Default value * @param null|Expr $default Default value
* @param null|Identifier|Name|ComplexType $type Type declaration * @param null|Identifier|Name|ComplexType $type Type declaration
* @param bool $byRef Whether is passed by reference * @param bool $byRef Whether is passed by reference
* @param bool $variadic Whether this is a variadic argument * @param bool $variadic Whether this is a variadic argument
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
* @param int $flags Optional visibility flags * @param int $flags Optional visibility flags
* @param list<AttributeGroup> $attrGroups PHP attribute groups * @param list<AttributeGroup> $attrGroups PHP attribute groups
*/ */
public function __construct( public function __construct(
$var, ?Expr $default = null, ?Node $type = null, Expr $var, ?Expr $default = null, ?Node $type = null,
bool $byRef = false, bool $variadic = false, bool $byRef = false, bool $variadic = false,
array $attributes = [], array $attributes = [],
int $flags = 0, int $flags = 0,

View File

@@ -8,7 +8,7 @@ use PhpParser\Node\Scalar;
class InterpolatedString extends Scalar { class InterpolatedString extends Scalar {
/** @var (Expr|InterpolatedStringPart)[] list of string parts */ /** @var (Expr|InterpolatedStringPart)[] list of string parts */
public $parts; public array $parts;
/** /**
* Constructs an interpolated string node. * Constructs an interpolated string node.

View File

@@ -13,7 +13,7 @@ class ClassConst extends Node\Stmt {
/** @var Node\AttributeGroup[] PHP attribute groups */ /** @var Node\AttributeGroup[] PHP attribute groups */
public array $attrGroups; public array $attrGroups;
/** @var Node\Identifier|Node\Name|Node\ComplexType|null Type declaration */ /** @var Node\Identifier|Node\Name|Node\ComplexType|null Type declaration */
public $type; public ?Node $type;
/** /**
* Constructs a class const list node. * Constructs a class const list node.

View File

@@ -16,7 +16,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike {
/** @var Node\Param[] Parameters */ /** @var Node\Param[] Parameters */
public array $params; public array $params;
/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */ /** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */
public $returnType; public ?Node $returnType;
/** @var Node\Stmt[]|null Statements */ /** @var Node\Stmt[]|null Statements */
public ?array $stmts; public ?array $stmts;
/** @var Node\AttributeGroup[] PHP attribute groups */ /** @var Node\AttributeGroup[] PHP attribute groups */

View File

@@ -6,7 +6,7 @@ use PhpParser\Node;
class Enum_ extends ClassLike { class Enum_ extends ClassLike {
/** @var null|Node\Identifier Scalar Type */ /** @var null|Node\Identifier Scalar Type */
public $scalarType; public ?Node $scalarType;
/** @var Node\Name[] Names of implemented interfaces */ /** @var Node\Name[] Names of implemented interfaces */
public array $implements; public array $implements;

View File

@@ -13,7 +13,7 @@ class Function_ extends Node\Stmt implements FunctionLike {
/** @var Node\Param[] Parameters */ /** @var Node\Param[] Parameters */
public array $params; public array $params;
/** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */ /** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */
public $returnType; public ?Node $returnType;
/** @var Node\Stmt[] Statements */ /** @var Node\Stmt[] Statements */
public array $stmts; public array $stmts;
/** @var Node\AttributeGroup[] PHP attribute groups */ /** @var Node\AttributeGroup[] PHP attribute groups */

View File

@@ -15,18 +15,18 @@ class Property extends Node\Stmt {
/** @var PropertyItem[] Properties */ /** @var PropertyItem[] Properties */
public array $props; public array $props;
/** @var null|Identifier|Name|ComplexType Type declaration */ /** @var null|Identifier|Name|ComplexType Type declaration */
public $type; public ?Node $type;
/** @var Node\AttributeGroup[] PHP attribute groups */ /** @var Node\AttributeGroup[] PHP attribute groups */
public array $attrGroups; public array $attrGroups;
/** /**
* Constructs a class property list node. * Constructs a class property list node.
* *
* @param int $flags Modifiers * @param int $flags Modifiers
* @param PropertyItem[] $props Properties * @param PropertyItem[] $props Properties
* @param array<string, mixed> $attributes Additional attributes * @param array<string, mixed> $attributes Additional attributes
* @param null|Identifier|Name|ComplexType $type Type declaration * @param null|Identifier|Name|ComplexType $type Type declaration
* @param Node\AttributeGroup[] $attrGroups PHP attribute groups * @param Node\AttributeGroup[] $attrGroups PHP attribute groups
*/ */
public function __construct(int $flags, array $props, array $attributes = [], ?Node $type = null, array $attrGroups = []) { public function __construct(int $flags, array $props, array $attributes = [], ?Node $type = null, array $attrGroups = []) {
$this->attributes = $attributes; $this->attributes = $attributes;

View File

@@ -4,7 +4,7 @@ namespace PhpParser\Node;
class UnionType extends ComplexType { class UnionType extends ComplexType {
/** @var (Identifier|Name|IntersectionType)[] Types */ /** @var (Identifier|Name|IntersectionType)[] Types */
public $types; public array $types;
/** /**
* Constructs a union type. * Constructs a union type.

View File

@@ -126,7 +126,7 @@ abstract class ParserAbstract implements Parser {
protected int $errorState; protected int $errorState;
/** @var \SplObjectStorage<Array_, null>|null Array nodes created during parsing, for postprocessing of empty elements. */ /** @var \SplObjectStorage<Array_, null>|null Array nodes created during parsing, for postprocessing of empty elements. */
protected $createdArrays; protected ?\SplObjectStorage $createdArrays;
/** @var Token[] Tokens for the current parse */ /** @var Token[] Tokens for the current parse */
protected array $tokens; protected array $tokens;

View File

@@ -3,6 +3,7 @@
namespace PhpParser; namespace PhpParser;
use PhpParser\Internal\DiffElem; use PhpParser\Internal\DiffElem;
use PhpParser\Internal\Differ;
use PhpParser\Internal\PrintableNewAnonClassNode; use PhpParser\Internal\PrintableNewAnonClassNode;
use PhpParser\Internal\TokenStream; use PhpParser\Internal\TokenStream;
use PhpParser\Node\AttributeGroup; use PhpParser\Node\AttributeGroup;
@@ -120,8 +121,8 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
/** @var TokenStream|null Original tokens for use in format-preserving pretty print */ /** @var TokenStream|null Original tokens for use in format-preserving pretty print */
protected ?TokenStream $origTokens; protected ?TokenStream $origTokens;
/** @var Internal\Differ<Node>|null Differ for node lists */ /** @var Internal\Differ<Node> Differ for node lists */
protected $nodeListDiffer; protected Differ $nodeListDiffer;
/** @var array<string, bool> Map determining whether a certain character is a label character */ /** @var array<string, bool> Map determining whether a certain character is a label character */
protected array $labelCharMap; protected array $labelCharMap;
/** /**
@@ -1273,7 +1274,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
* The node list differ is used to determine differences between two array subnodes. * The node list differ is used to determine differences between two array subnodes.
*/ */
protected function initializeNodeListDiffer(): void { protected function initializeNodeListDiffer(): void {
if ($this->nodeListDiffer) { if (isset($this->nodeListDiffer)) {
return; return;
} }

View File

@@ -108,7 +108,7 @@ class FunctionTest extends \PHPUnit\Framework\TestCase {
->getNode(); ->getNode();
$this->assertEquals(new Stmt\Function_('test', [ $this->assertEquals(new Stmt\Function_('test', [
'returnType' => 'void' 'returnType' => new Identifier('void'),
], []), $node); ], []), $node);
} }

View File

@@ -149,7 +149,7 @@ class MethodTest extends \PHPUnit\Framework\TestCase {
->setReturnType('bool') ->setReturnType('bool')
->getNode(); ->getNode();
$this->assertEquals(new Stmt\ClassMethod('test', [ $this->assertEquals(new Stmt\ClassMethod('test', [
'returnType' => 'bool' 'returnType' => new Identifier('bool'),
], []), $node); ], []), $node);
} }