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
4 changes: 3 additions & 1 deletion src/Type/ExplicitType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ public function getTypeIdentifier(): TypeIdentifier

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

public function getExplicitType(): string
Expand Down
9 changes: 8 additions & 1 deletion src/TypeFactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ trait TypeFactoryTrait
{
use BaseTypeFactoryTrait;

public static function explicit(TypeIdentifier|string $identifier, string $explicitType): ExplicitType
/**
* @template T of TypeIdentifier
*
* @param T $identifier
*
* @return ExplicitType<T>
*/
public static function explicit(TypeIdentifier $identifier, string $explicitType): ExplicitType
{
return new ExplicitType($identifier, $explicitType);
}
Expand Down
4 changes: 2 additions & 2 deletions src/TypeResolver/ResolverExtrasTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function resolveIntRange(GenericTypeNode $node): IntRangeType
}

/**
* @param array<BaseType> $variableTypes
* @param list<BaseType> $variableTypes
*/
protected function tryAsClassLike(BaseType $type, array $variableTypes): ?ClassLikeType
{
Expand All @@ -53,7 +53,7 @@ protected function tryAsClassLike(BaseType $type, array $variableTypes): ?ClassL
return null;
}

public function reduceToBuiltinType(?BaseType $type)
public function reduceToBuiltinType(?BaseType $type): ?BaseType
{
return $type instanceof ExplicitType
? $type->getBuiltinType()
Expand Down
6 changes: 3 additions & 3 deletions tests/Type/ExplicitTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

class ExplicitTypeTest extends TestCase
{
public function testToString()
public function testToString(): void
{
$this->assertSame('numeric-int', (string) new ExplicitType(TypeIdentifier::INT, 'numeric-int'));
}

public function testIsIdentifiedBy()
public function testIsIdentifiedBy(): void
{
$this->assertFalse((new ExplicitType(TypeIdentifier::INT, 'numeric-int'))->isIdentifiedBy(TypeIdentifier::ARRAY));
$this->assertTrue((new ExplicitType(TypeIdentifier::INT, 'numeric-int'))->isIdentifiedBy(TypeIdentifier::INT));
Expand All @@ -23,7 +23,7 @@ public function testIsIdentifiedBy()
$this->assertTrue((new ExplicitType(TypeIdentifier::INT, 'numeric-int'))->isIdentifiedBy('string', 'int'));
}

public function testIsNullable()
public function testIsNullable(): void
{
$this->assertFalse((new ExplicitType(TypeIdentifier::INT, 'numeric-int'))->isNullable());
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Type/IntRangeTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class IntRangeTypeTest extends TestCase
{
public function testToString()
public function testToString(): void
{
$this->assertSame('int<0, max>', (string) new IntRangeType(from: 0, explicitType: 'int<0, max>'));
$this->assertSame('int<min, 0>', (string) new IntRangeType(to: 0, explicitType: 'int<min, 0>'));
Expand All @@ -21,7 +21,7 @@ public function testToString()
$this->assertSame('int<min, 5>', (string) new IntRangeType(to: 5, explicitType: 'int<min, 5>'));
}

public function testAccepts()
public function testAccepts(): void
{
$this->assertFalse((new IntRangeType(from: 0, to: 5, explicitType: 'int<0, 5>'))->accepts('string'));
$this->assertFalse((new IntRangeType(from: 0, to: 5, explicitType: 'int<0, 5>'))->accepts([]));
Expand Down
7 changes: 5 additions & 2 deletions tests/TypeResolver/StringTypeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ protected function setUp(): void
$this->resolver = new StringTypeResolver();
}

/**
* @return iterable<array{BaseType, string, 2?: TypeContext|null}>
*/
public static function extrasResolveDataProvider(): iterable
{
foreach (parent::resolveDataProvider() as $key => $set) {
Expand Down Expand Up @@ -71,13 +74,13 @@ public static function extrasResolveDataProvider(): iterable
}

#[DataProvider('extrasResolveDataProvider')]
public function testResolve(BaseType $expectedType, string $string, ?TypeContext $typeContext = null)
public function testResolve(BaseType $expectedType, string $string, ?TypeContext $typeContext = null): void
{
$this->assertEquals($expectedType, $this->resolver->resolve($string, $typeContext));
}

#[DataProvider('extrasResolveDataProvider')]
public function testResolveStringable(BaseType $expectedType, string $string, ?TypeContext $typeContext = null)
public function testResolveStringable(BaseType $expectedType, string $string, ?TypeContext $typeContext = null): void
{
$this->assertEquals($expectedType, $this->resolver->resolve(new class ($string) implements \Stringable {
public function __construct(private string $value)
Expand Down