diff --git a/lib/PhpParser/Builder/Param.php b/lib/PhpParser/Builder/Param.php index 0ea91683..90bbb603 100644 --- a/lib/PhpParser/Builder/Param.php +++ b/lib/PhpParser/Builder/Param.php @@ -47,7 +47,7 @@ class Param implements PhpParser\Builder /** * Sets type for the parameter. * - * @param string|Node\Name|Node\NullableType|Node\UnionType $type Parameter type + * @param string|Node\Name|Node\ComplexType $type Parameter type * * @return $this The builder instance (for fluid interface) */ @@ -63,7 +63,7 @@ class Param implements PhpParser\Builder /** * Sets type for the parameter. * - * @param string|Node\Name|Node\NullableType|Node\UnionType $type Parameter type + * @param string|Node\Name|Node\ComplexType $type Parameter type * * @return $this The builder instance (for fluid interface) * diff --git a/lib/PhpParser/BuilderHelpers.php b/lib/PhpParser/BuilderHelpers.php index 835e929f..2f0e9127 100644 --- a/lib/PhpParser/BuilderHelpers.php +++ b/lib/PhpParser/BuilderHelpers.php @@ -2,13 +2,13 @@ namespace PhpParser; +use PhpParser\Node\ComplexType; use PhpParser\Node\Expr; use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\NullableType; use PhpParser\Node\Scalar; use PhpParser\Node\Stmt; -use PhpParser\Node\UnionType; /** * This class defines helpers used in the implementation of builders. Don't use it directly. @@ -154,18 +154,18 @@ final class BuilderHelpers * In particular, builtin types become Identifiers, custom types become Names and nullables * are wrapped in NullableType nodes. * - * @param string|Name|Identifier|NullableType|UnionType $type The type to normalize + * @param string|Name|Identifier|ComplexType $type The type to normalize * - * @return Name|Identifier|NullableType|UnionType The normalized type + * @return Name|Identifier|ComplexType The normalized type */ public static function normalizeType($type) { if (!is_string($type)) { if ( !$type instanceof Name && !$type instanceof Identifier && - !$type instanceof NullableType && !$type instanceof UnionType + !$type instanceof ComplexType ) { throw new \LogicException( - 'Type must be a string, or an instance of Name, Identifier, NullableType or UnionType' + 'Type must be a string, or an instance of Name, Identifier or ComplexType' ); } return $type; diff --git a/lib/PhpParser/Node/ComplexType.php b/lib/PhpParser/Node/ComplexType.php new file mode 100644 index 00000000..9505532a --- /dev/null +++ b/lib/PhpParser/Node/ComplexType.php @@ -0,0 +1,14 @@ +attributes = $attributes; diff --git a/lib/PhpParser/Node/UnionType.php b/lib/PhpParser/Node/UnionType.php index c8f45235..61c2d810 100644 --- a/lib/PhpParser/Node/UnionType.php +++ b/lib/PhpParser/Node/UnionType.php @@ -2,9 +2,7 @@ namespace PhpParser\Node; -use PhpParser\NodeAbstract; - -class UnionType extends NodeAbstract +class UnionType extends ComplexType { /** @var (Identifier|Name)[] Types */ public $types; diff --git a/test/PhpParser/Builder/ParamTest.php b/test/PhpParser/Builder/ParamTest.php index 05b3c912..9fe81607 100644 --- a/test/PhpParser/Builder/ParamTest.php +++ b/test/PhpParser/Builder/ParamTest.php @@ -177,7 +177,7 @@ class ParamTest extends \PHPUnit\Framework\TestCase public function testInvalidTypeError() { $this->expectException(\LogicException::class); - $this->expectExceptionMessage('Type must be a string, or an instance of Name, Identifier, NullableType or UnionType'); + $this->expectExceptionMessage('Type must be a string, or an instance of Name, Identifier or ComplexType'); $this->createParamBuilder('test')->setType(new \stdClass); } diff --git a/test/PhpParser/BuilderHelpersTest.php b/test/PhpParser/BuilderHelpersTest.php index da6348f6..c848dbb6 100644 --- a/test/PhpParser/BuilderHelpersTest.php +++ b/test/PhpParser/BuilderHelpersTest.php @@ -146,7 +146,7 @@ class BuilderHelpersTest extends \PHPUnit\Framework\TestCase $this->assertEquals($intIdentifier, $nullable->type); $this->expectException(\LogicException::class); - $this->expectExceptionMessage('Type must be a string, or an instance of Name, Identifier, NullableType or UnionType'); + $this->expectExceptionMessage('Type must be a string, or an instance of Name, Identifier or ComplexType'); BuilderHelpers::normalizeType(1); }