Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Type/ExplicitType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Radebatz\TypeInfoExtras\Type;

use Symfony\Component\TypeInfo\Type;
use Symfony\Component\TypeInfo\Type\BuiltinType;
use Symfony\Component\TypeInfo\TypeIdentifier;

/**
Expand Down Expand Up @@ -31,6 +32,14 @@ public function getTypeIdentifier(): TypeIdentifier
return $this->typeIdentifier;
}

/**
* Get the underlying builtin type.
*/
public function getBuiltinType(): BuiltinType
{
return Type::builtin($this->typeIdentifier);
}

public function getExplicitType(): string
{
return $this->explicitType;
Expand Down
7 changes: 7 additions & 0 deletions src/TypeResolver/ResolverExtrasTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ protected function tryAsClassLike(BaseType $type, array $variableTypes): ?ClassL

return null;
}

public function reduceToBuiltinType(?BaseType $type)
{
return $type instanceof ExplicitType
? $type->getBuiltinType()
: $type;
}
}
2 changes: 1 addition & 1 deletion src/TypeResolver/StringTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private function getTypeFromNode(TypeNode $node, ?TypeContext $typeContext): Bas
throw new \DomainException(\sprintf('"%s" type cannot have a key type defined.', $node->type));
}

return Type::collection($type, $variableTypes[1], $variableTypes[0], $asList);
return Type::collection($type, $variableTypes[1], $this->reduceToBuiltinType($variableTypes[0]), $asList);
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/TypeResolver/StringTypeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static function extrasResolveDataProvider(): iterable
yield [Type::union(Type::intRange(to: -1), Type::intRange(from: 1)), 'non-zero-int'];
yield [Type::intRange(0, 100), 'int<0, 100>'];
yield [Type::intRange(), 'int<min, max>'];
yield [Type::array(Type::bool(), Type::int()), 'array<positive-int, bool>'];

yield [Type::explicit(TypeIdentifier::STRING, 'class-string'), 'class-string'];
yield [Type::classLike('class-string', Type::object(Dummy::class)), sprintf('class-string<%s>', Dummy::class)];
Expand Down