diff --git a/lib/PhpParser/Node/Expr/ArrowFunction.php b/lib/PhpParser/Node/Expr/ArrowFunction.php index 98e24a51..f9b4ec36 100644 --- a/lib/PhpParser/Node/Expr/ArrowFunction.php +++ b/lib/PhpParser/Node/Expr/ArrowFunction.php @@ -30,7 +30,7 @@ class ArrowFunction extends Expr implements FunctionLike { * static?: bool, * byRef?: bool, * params?: Node\Param[], - * returnType?: null|string|Node\Identifier|Node\Name|Node\ComplexType, + * returnType?: null|Node\Identifier|Node\Name|Node\ComplexType, * attrGroups?: Node\AttributeGroup[] * } $subNodes Array of the following subnodes: * 'expr' : Expression body @@ -46,8 +46,7 @@ class ArrowFunction extends Expr implements FunctionLike { $this->static = $subNodes['static'] ?? false; $this->byRef = $subNodes['byRef'] ?? false; $this->params = $subNodes['params'] ?? []; - $returnType = $subNodes['returnType'] ?? null; - $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType; + $this->returnType = $subNodes['returnType'] ?? null; $this->expr = $subNodes['expr']; $this->attrGroups = $subNodes['attrGroups'] ?? []; } diff --git a/lib/PhpParser/Node/Expr/Closure.php b/lib/PhpParser/Node/Expr/Closure.php index ee257d49..ddb4e0b7 100644 --- a/lib/PhpParser/Node/Expr/Closure.php +++ b/lib/PhpParser/Node/Expr/Closure.php @@ -31,7 +31,7 @@ class Closure extends Expr implements FunctionLike { * byRef?: bool, * params?: Node\Param[], * uses?: ClosureUse[], - * returnType?: null|string|Node\Identifier|Node\Name|Node\ComplexType, + * returnType?: null|Node\Identifier|Node\Name|Node\ComplexType, * stmts?: Node\Stmt[], * attrGroups?: Node\AttributeGroup[], * } $subNodes Array of the following optional subnodes: @@ -50,8 +50,7 @@ class Closure extends Expr implements FunctionLike { $this->byRef = $subNodes['byRef'] ?? false; $this->params = $subNodes['params'] ?? []; $this->uses = $subNodes['uses'] ?? []; - $returnType = $subNodes['returnType'] ?? null; - $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType; + $this->returnType = $subNodes['returnType'] ?? null; $this->stmts = $subNodes['stmts'] ?? []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } diff --git a/lib/PhpParser/Node/NullableType.php b/lib/PhpParser/Node/NullableType.php index e86d0974..847b6573 100644 --- a/lib/PhpParser/Node/NullableType.php +++ b/lib/PhpParser/Node/NullableType.php @@ -2,6 +2,8 @@ namespace PhpParser\Node; +use PhpParser\Node; + class NullableType extends ComplexType { /** @var Identifier|Name Type */ public $type; @@ -9,12 +11,12 @@ class NullableType extends ComplexType { /** * Constructs a nullable type (wrapping another type). * - * @param string|Identifier|Name $type Type + * @param Identifier|Name $type Type * @param array $attributes Additional attributes */ - public function __construct($type, array $attributes = []) { + public function __construct(Node $type, array $attributes = []) { $this->attributes = $attributes; - $this->type = \is_string($type) ? new Identifier($type) : $type; + $this->type = $type; } public function getSubNodeNames(): array { diff --git a/lib/PhpParser/Node/Param.php b/lib/PhpParser/Node/Param.php index ef110531..0732c574 100644 --- a/lib/PhpParser/Node/Param.php +++ b/lib/PhpParser/Node/Param.php @@ -3,6 +3,7 @@ namespace PhpParser\Node; use PhpParser\Modifiers; +use PhpParser\Node; use PhpParser\NodeAbstract; class Param extends NodeAbstract { @@ -26,7 +27,7 @@ class Param extends NodeAbstract { * * @param Expr\Variable|Expr\Error $var Parameter variable * @param null|Expr $default Default value - * @param null|string|Identifier|Name|ComplexType $type Type declaration + * @param null|Identifier|Name|ComplexType $type Type declaration * @param bool $byRef Whether is passed by reference * @param bool $variadic Whether this is a variadic argument * @param array $attributes Additional attributes @@ -34,14 +35,14 @@ class Param extends NodeAbstract { * @param list $attrGroups PHP attribute groups */ public function __construct( - $var, ?Expr $default = null, $type = null, + $var, ?Expr $default = null, ?Node $type = null, bool $byRef = false, bool $variadic = false, array $attributes = [], int $flags = 0, array $attrGroups = [] ) { $this->attributes = $attributes; - $this->type = \is_string($type) ? new Identifier($type) : $type; + $this->type = $type; $this->byRef = $byRef; $this->variadic = $variadic; $this->var = $var; diff --git a/lib/PhpParser/Node/Stmt/ClassConst.php b/lib/PhpParser/Node/Stmt/ClassConst.php index 44f0cc31..a5e467ab 100644 --- a/lib/PhpParser/Node/Stmt/ClassConst.php +++ b/lib/PhpParser/Node/Stmt/ClassConst.php @@ -22,20 +22,20 @@ class ClassConst extends Node\Stmt { * @param int $flags Modifiers * @param array $attributes Additional attributes * @param list $attrGroups PHP attribute groups - * @param null|string|Node\Identifier|Node\Name|Node\ComplexType $type Type declaration + * @param null|Node\Identifier|Node\Name|Node\ComplexType $type Type declaration */ public function __construct( array $consts, int $flags = 0, array $attributes = [], array $attrGroups = [], - $type = null + ?Node $type = null ) { $this->attributes = $attributes; $this->flags = $flags; $this->consts = $consts; $this->attrGroups = $attrGroups; - $this->type = \is_string($type) ? new Node\Identifier($type) : $type; + $this->type = $type; } public function getSubNodeNames(): array { diff --git a/lib/PhpParser/Node/Stmt/ClassMethod.php b/lib/PhpParser/Node/Stmt/ClassMethod.php index 3cadfd86..aa6424b6 100644 --- a/lib/PhpParser/Node/Stmt/ClassMethod.php +++ b/lib/PhpParser/Node/Stmt/ClassMethod.php @@ -51,7 +51,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike { * flags?: int, * byRef?: bool, * params?: Node\Param[], - * returnType?: null|string|Node\Identifier|Node\Name|Node\ComplexType, + * returnType?: null|Node\Identifier|Node\Name|Node\ComplexType, * stmts?: Node\Stmt[]|null, * attrGroups?: Node\AttributeGroup[], * } $subNodes Array of the following optional subnodes: @@ -69,8 +69,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike { $this->byRef = $subNodes['byRef'] ?? false; $this->name = \is_string($name) ? new Node\Identifier($name) : $name; $this->params = $subNodes['params'] ?? []; - $returnType = $subNodes['returnType'] ?? null; - $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType; + $this->returnType = $subNodes['returnType'] ?? null; $this->stmts = array_key_exists('stmts', $subNodes) ? $subNodes['stmts'] : []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } diff --git a/lib/PhpParser/Node/Stmt/Function_.php b/lib/PhpParser/Node/Stmt/Function_.php index 8948e211..feb5edfe 100644 --- a/lib/PhpParser/Node/Stmt/Function_.php +++ b/lib/PhpParser/Node/Stmt/Function_.php @@ -29,7 +29,7 @@ class Function_ extends Node\Stmt implements FunctionLike { * @param array{ * byRef?: bool, * params?: Node\Param[], - * returnType?: null|string|Node\Identifier|Node\Name|Node\ComplexType, + * returnType?: null|Node\Identifier|Node\Name|Node\ComplexType, * stmts?: Node\Stmt[], * attrGroups?: Node\AttributeGroup[], * } $subNodes Array of the following optional subnodes: @@ -45,8 +45,7 @@ class Function_ extends Node\Stmt implements FunctionLike { $this->byRef = $subNodes['byRef'] ?? false; $this->name = \is_string($name) ? new Node\Identifier($name) : $name; $this->params = $subNodes['params'] ?? []; - $returnType = $subNodes['returnType'] ?? null; - $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType; + $this->returnType = $subNodes['returnType'] ?? null; $this->stmts = $subNodes['stmts'] ?? []; $this->attrGroups = $subNodes['attrGroups'] ?? []; } diff --git a/lib/PhpParser/Node/Stmt/Property.php b/lib/PhpParser/Node/Stmt/Property.php index 279207fd..5d668274 100644 --- a/lib/PhpParser/Node/Stmt/Property.php +++ b/lib/PhpParser/Node/Stmt/Property.php @@ -25,14 +25,14 @@ class Property extends Node\Stmt { * @param int $flags Modifiers * @param PropertyItem[] $props Properties * @param array $attributes Additional attributes - * @param null|string|Identifier|Name|ComplexType $type Type declaration + * @param null|Identifier|Name|ComplexType $type Type declaration * @param Node\AttributeGroup[] $attrGroups PHP attribute groups */ - public function __construct(int $flags, array $props, array $attributes = [], $type = null, array $attrGroups = []) { + public function __construct(int $flags, array $props, array $attributes = [], ?Node $type = null, array $attrGroups = []) { $this->attributes = $attributes; $this->flags = $flags; $this->props = $props; - $this->type = \is_string($type) ? new Identifier($type) : $type; + $this->type = $type; $this->attrGroups = $attrGroups; } diff --git a/test/PhpParser/BuilderHelpersTest.php b/test/PhpParser/BuilderHelpersTest.php index 493e71e9..d70be9d8 100644 --- a/test/PhpParser/BuilderHelpersTest.php +++ b/test/PhpParser/BuilderHelpersTest.php @@ -3,6 +3,7 @@ namespace PhpParser; use PhpParser\Builder\Class_; +use PhpParser\Node\Identifier; use PhpParser\Node\Scalar; use PhpParser\Node\Stmt; use PhpParser\Node\Expr; @@ -136,7 +137,7 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase { $intName = new Node\Name('int'); $this->assertSame($intName, BuilderHelpers::normalizeType($intName)); - $intNullable = new Node\NullableType('int'); + $intNullable = new Node\NullableType(new Identifier('int')); $this->assertSame($intNullable, BuilderHelpers::normalizeType($intNullable)); $unionType = new Node\UnionType([new Node\Identifier('int'), new Node\Identifier('string')]);