diff --git a/src/Type/ExplicitType.php b/src/Type/ExplicitType.php index 397282f..8d44672 100644 --- a/src/Type/ExplicitType.php +++ b/src/Type/ExplicitType.php @@ -34,10 +34,12 @@ public function getTypeIdentifier(): TypeIdentifier /** * Get the underlying builtin type. + * + * @return BuiltinType */ public function getBuiltinType(): BuiltinType { - return Type::builtin($this->typeIdentifier); + return new BuiltinType($this->typeIdentifier); } public function getExplicitType(): string diff --git a/src/TypeFactoryTrait.php b/src/TypeFactoryTrait.php index 2122255..73480e7 100644 --- a/src/TypeFactoryTrait.php +++ b/src/TypeFactoryTrait.php @@ -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 + */ + public static function explicit(TypeIdentifier $identifier, string $explicitType): ExplicitType { return new ExplicitType($identifier, $explicitType); } diff --git a/src/TypeResolver/ResolverExtrasTrait.php b/src/TypeResolver/ResolverExtrasTrait.php index 3467774..4237e7e 100644 --- a/src/TypeResolver/ResolverExtrasTrait.php +++ b/src/TypeResolver/ResolverExtrasTrait.php @@ -40,7 +40,7 @@ protected function resolveIntRange(GenericTypeNode $node): IntRangeType } /** - * @param array $variableTypes + * @param list $variableTypes */ protected function tryAsClassLike(BaseType $type, array $variableTypes): ?ClassLikeType { @@ -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() diff --git a/tests/Type/ExplicitTypeTest.php b/tests/Type/ExplicitTypeTest.php index 583aeac..0cd9110 100644 --- a/tests/Type/ExplicitTypeTest.php +++ b/tests/Type/ExplicitTypeTest.php @@ -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)); @@ -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()); } diff --git a/tests/Type/IntRangeTypeTest.php b/tests/Type/IntRangeTypeTest.php index 05f9ac8..7eeeda1 100644 --- a/tests/Type/IntRangeTypeTest.php +++ b/tests/Type/IntRangeTypeTest.php @@ -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', (string) new IntRangeType(to: 0, explicitType: 'int')); @@ -21,7 +21,7 @@ public function testToString() $this->assertSame('int', (string) new IntRangeType(to: 5, explicitType: 'int')); } - 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([])); diff --git a/tests/TypeResolver/StringTypeResolverTest.php b/tests/TypeResolver/StringTypeResolverTest.php index f594546..b6e0582 100644 --- a/tests/TypeResolver/StringTypeResolverTest.php +++ b/tests/TypeResolver/StringTypeResolverTest.php @@ -31,6 +31,9 @@ protected function setUp(): void $this->resolver = new StringTypeResolver(); } + /** + * @return iterable + */ public static function extrasResolveDataProvider(): iterable { foreach (parent::resolveDataProvider() as $key => $set) { @@ -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)