Skip to content

Commit

Permalink
Get rid of PhpParser\Node\ComplexType
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Oct 14, 2021
1 parent 9abd6cc commit 11ef581
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/Reflection/ReflectionFunctionAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ public function getDocBlockReturnTypes(): array
public function getReturnType(): ReflectionNamedType|ReflectionUnionType|null
{
$returnType = $this->node->getReturnType();
assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || $returnType instanceof Node\IntersectionType || $returnType === null);

if ($returnType === null) {
return null;
Expand Down
1 change: 1 addition & 0 deletions src/Reflection/ReflectionParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public function getPosition(): int
public function getType(): ReflectionNamedType|ReflectionUnionType|null
{
$type = $this->node->type;
assert($type instanceof Node\Identifier || $type instanceof Node\Name || $type instanceof Node\NullableType || $type instanceof Node\UnionType || $type instanceof Node\IntersectionType || $type === null);

if ($type === null) {
return null;
Expand Down
2 changes: 2 additions & 0 deletions src/Reflection/ReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Throwable;
use Webmozart\Assert\Assert;

use function assert;
use function class_exists;
use function func_num_args;
use function is_object;
Expand Down Expand Up @@ -440,6 +441,7 @@ public function allowsNull(): bool
public function getType(): ReflectionNamedType|ReflectionUnionType|null
{
$type = $this->node->type;
assert($type instanceof Node\Identifier || $type instanceof Node\Name || $type instanceof Node\NullableType || $type instanceof Node\UnionType || $type instanceof Node\IntersectionType || $type === null);

if ($type === null) {
return null;
Expand Down
14 changes: 8 additions & 6 deletions src/Reflection/ReflectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@

namespace Roave\BetterReflection\Reflection;

use PhpParser\Node\ComplexType;
use PhpParser\Node\Identifier;
use PhpParser\Node\IntersectionType;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
use PhpParser\Node\UnionType;
use PHPStan\BetterReflection\Reflection\Adapter\Exception\NotImplemented;

abstract class ReflectionType
{
protected function __construct(private bool $allowsNull)
{
}

public static function createFromTypeAndReflector(Identifier|Name|ComplexType $type, bool $forceAllowsNull = false): ReflectionNamedType|ReflectionUnionType
public static function createFromTypeAndReflector(Identifier|Name|NullableType|UnionType|IntersectionType $type, bool $forceAllowsNull = false): ReflectionNamedType|ReflectionUnionType
{
$allowsNull = $forceAllowsNull;
if ($type instanceof NullableType) {
Expand All @@ -27,10 +29,10 @@ public static function createFromTypeAndReflector(Identifier|Name|ComplexType $t
return new ReflectionNamedType($type, $allowsNull);
}

/**
* @psalm-suppress ArgumentTypeCoercion
* @phpstan-ignore-next-line
*/
if ($type instanceof IntersectionType) {
throw new NotImplemented('Not implemented');
}

return new ReflectionUnionType($type, $allowsNull);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ private function setParameterDefaultValue(ReflectionParameter $parameterReflecti
$parameterNode->setDefault($parameterReflection->getDefaultValue());
}

private function formatType(CoreReflectionNamedType|CoreReflectionUnionType $type): Name|FullyQualified|Node\ComplexType
private function formatType(CoreReflectionNamedType|CoreReflectionUnionType $type): Name|FullyQualified|Node\NullableType|Node\UnionType
{
if ($type instanceof CoreReflectionUnionType) {
$types = [];
Expand Down

0 comments on commit 11ef581

Please sign in to comment.