From 08dbe8266a29c86093a57e074537f64cecba70f7 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 31 May 2024 11:00:14 +0200 Subject: [PATCH] Template tag name cannot be empty string --- src/PhpDoc/Tag/TemplateTag.php | 6 +++ src/Type/CallableType.php | 4 +- src/Type/ClosureType.php | 4 +- src/Type/Generic/TemplateArrayType.php | 3 ++ .../Generic/TemplateBenevolentUnionType.php | 3 ++ src/Type/Generic/TemplateBooleanType.php | 3 ++ .../Generic/TemplateConstantArrayType.php | 3 ++ .../Generic/TemplateConstantIntegerType.php | 3 ++ .../Generic/TemplateConstantStringType.php | 3 ++ src/Type/Generic/TemplateFloatType.php | 3 ++ .../Generic/TemplateGenericObjectType.php | 3 ++ src/Type/Generic/TemplateIntegerType.php | 3 ++ src/Type/Generic/TemplateIntersectionType.php | 3 ++ src/Type/Generic/TemplateKeyOfType.php | 3 ++ src/Type/Generic/TemplateMixedType.php | 3 ++ src/Type/Generic/TemplateObjectShapeType.php | 3 ++ src/Type/Generic/TemplateObjectType.php | 3 ++ .../TemplateObjectWithoutClassType.php | 3 ++ src/Type/Generic/TemplateStrictMixedType.php | 3 ++ src/Type/Generic/TemplateStringType.php | 3 ++ src/Type/Generic/TemplateType.php | 1 + src/Type/Generic/TemplateTypeFactory.php | 3 ++ src/Type/Generic/TemplateTypeTrait.php | 2 + src/Type/Generic/TemplateUnionType.php | 3 ++ .../GenericParametersAcceptorResolverTest.php | 15 +++--- tests/PHPStan/Type/ArrayTypeTest.php | 15 +++--- tests/PHPStan/Type/CallableTypeTest.php | 15 +++--- .../Type/Constant/ConstantArrayTypeTest.php | 15 +++--- .../Type/Generic/GenericObjectTypeTest.php | 30 +++++++----- tests/PHPStan/Type/IterableTypeTest.php | 15 +++--- tests/PHPStan/Type/TemplateTypeTest.php | 46 +++++++++++-------- 31 files changed, 160 insertions(+), 65 deletions(-) diff --git a/src/PhpDoc/Tag/TemplateTag.php b/src/PhpDoc/Tag/TemplateTag.php index 4a2180c052..78707555c8 100644 --- a/src/PhpDoc/Tag/TemplateTag.php +++ b/src/PhpDoc/Tag/TemplateTag.php @@ -9,10 +9,16 @@ class TemplateTag { + /** + * @param non-empty-string $name + */ public function __construct(private string $name, private Type $bound, private TemplateTypeVariance $variance) { } + /** + * @return non-empty-string + */ public function getName(): string { return $this->name; diff --git a/src/Type/CallableType.php b/src/Type/CallableType.php index 5986ed81fa..1f8b5981a9 100644 --- a/src/Type/CallableType.php +++ b/src/Type/CallableType.php @@ -68,7 +68,7 @@ class CallableType implements CompoundType, CallableParametersAcceptor /** * @api * @param array|null $parameters - * @param array $templateTags + * @param array $templateTags */ public function __construct( ?array $parameters = null, @@ -89,7 +89,7 @@ public function __construct( } /** - * @return array + * @return array */ public function getTemplateTags(): array { diff --git a/src/Type/ClosureType.php b/src/Type/ClosureType.php index d637fdd24d..d86f117119 100644 --- a/src/Type/ClosureType.php +++ b/src/Type/ClosureType.php @@ -78,7 +78,7 @@ class ClosureType implements TypeWithClassName, CallableParametersAcceptor /** * @api * @param array|null $parameters - * @param array $templateTags + * @param array $templateTags * @param SimpleThrowPoint[] $throwPoints * @param SimpleImpurePoint[] $impurePoints * @param InvalidateExprNode[] $invalidateExpressions @@ -108,7 +108,7 @@ public function __construct( } /** - * @return array + * @return array */ public function getTemplateTags(): array { diff --git a/src/Type/Generic/TemplateArrayType.php b/src/Type/Generic/TemplateArrayType.php index 696deb7f04..bb0192d02b 100644 --- a/src/Type/Generic/TemplateArrayType.php +++ b/src/Type/Generic/TemplateArrayType.php @@ -13,6 +13,9 @@ final class TemplateArrayType extends ArrayType implements TemplateType use TemplateTypeTrait; use UndecidedComparisonCompoundTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateBenevolentUnionType.php b/src/Type/Generic/TemplateBenevolentUnionType.php index 9150bd4480..3107542f29 100644 --- a/src/Type/Generic/TemplateBenevolentUnionType.php +++ b/src/Type/Generic/TemplateBenevolentUnionType.php @@ -12,6 +12,9 @@ final class TemplateBenevolentUnionType extends BenevolentUnionType implements T /** @use TemplateTypeTrait */ use TemplateTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateBooleanType.php b/src/Type/Generic/TemplateBooleanType.php index 7962d50d0e..66ce5db4ec 100644 --- a/src/Type/Generic/TemplateBooleanType.php +++ b/src/Type/Generic/TemplateBooleanType.php @@ -13,6 +13,9 @@ final class TemplateBooleanType extends BooleanType implements TemplateType use TemplateTypeTrait; use UndecidedComparisonCompoundTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateConstantArrayType.php b/src/Type/Generic/TemplateConstantArrayType.php index 8bb8aa696d..b291dab577 100644 --- a/src/Type/Generic/TemplateConstantArrayType.php +++ b/src/Type/Generic/TemplateConstantArrayType.php @@ -13,6 +13,9 @@ final class TemplateConstantArrayType extends ConstantArrayType implements Templ use TemplateTypeTrait; use UndecidedComparisonCompoundTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateConstantIntegerType.php b/src/Type/Generic/TemplateConstantIntegerType.php index 4aa00d7805..e411af4edc 100644 --- a/src/Type/Generic/TemplateConstantIntegerType.php +++ b/src/Type/Generic/TemplateConstantIntegerType.php @@ -13,6 +13,9 @@ final class TemplateConstantIntegerType extends ConstantIntegerType implements T use TemplateTypeTrait; use UndecidedComparisonCompoundTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateConstantStringType.php b/src/Type/Generic/TemplateConstantStringType.php index 85c871e277..bcb3b0cf94 100644 --- a/src/Type/Generic/TemplateConstantStringType.php +++ b/src/Type/Generic/TemplateConstantStringType.php @@ -13,6 +13,9 @@ final class TemplateConstantStringType extends ConstantStringType implements Tem use TemplateTypeTrait; use UndecidedComparisonCompoundTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateFloatType.php b/src/Type/Generic/TemplateFloatType.php index f7e2210e86..32332bb3ef 100644 --- a/src/Type/Generic/TemplateFloatType.php +++ b/src/Type/Generic/TemplateFloatType.php @@ -13,6 +13,9 @@ final class TemplateFloatType extends FloatType implements TemplateType use TemplateTypeTrait; use UndecidedComparisonCompoundTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateGenericObjectType.php b/src/Type/Generic/TemplateGenericObjectType.php index 485781aaca..3810841ec9 100644 --- a/src/Type/Generic/TemplateGenericObjectType.php +++ b/src/Type/Generic/TemplateGenericObjectType.php @@ -13,6 +13,9 @@ final class TemplateGenericObjectType extends GenericObjectType implements Templ /** @use TemplateTypeTrait */ use TemplateTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateIntegerType.php b/src/Type/Generic/TemplateIntegerType.php index 62222f6b8e..64c631980d 100644 --- a/src/Type/Generic/TemplateIntegerType.php +++ b/src/Type/Generic/TemplateIntegerType.php @@ -13,6 +13,9 @@ final class TemplateIntegerType extends IntegerType implements TemplateType use TemplateTypeTrait; use UndecidedComparisonCompoundTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateIntersectionType.php b/src/Type/Generic/TemplateIntersectionType.php index 805739874a..87f1ca18a7 100644 --- a/src/Type/Generic/TemplateIntersectionType.php +++ b/src/Type/Generic/TemplateIntersectionType.php @@ -11,6 +11,9 @@ final class TemplateIntersectionType extends IntersectionType implements Templat /** @use TemplateTypeTrait */ use TemplateTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateKeyOfType.php b/src/Type/Generic/TemplateKeyOfType.php index 003de6f431..7312ea2ef4 100644 --- a/src/Type/Generic/TemplateKeyOfType.php +++ b/src/Type/Generic/TemplateKeyOfType.php @@ -14,6 +14,9 @@ final class TemplateKeyOfType extends KeyOfType implements TemplateType use TemplateTypeTrait; use UndecidedComparisonCompoundTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateMixedType.php b/src/Type/Generic/TemplateMixedType.php index 11af221db4..3363818673 100644 --- a/src/Type/Generic/TemplateMixedType.php +++ b/src/Type/Generic/TemplateMixedType.php @@ -15,6 +15,9 @@ final class TemplateMixedType extends MixedType implements TemplateType /** @use TemplateTypeTrait */ use TemplateTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateObjectShapeType.php b/src/Type/Generic/TemplateObjectShapeType.php index 7fe78cbdbd..5b1f187c6d 100644 --- a/src/Type/Generic/TemplateObjectShapeType.php +++ b/src/Type/Generic/TemplateObjectShapeType.php @@ -13,6 +13,9 @@ final class TemplateObjectShapeType extends ObjectShapeType implements TemplateT use TemplateTypeTrait; use UndecidedComparisonCompoundTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateObjectType.php b/src/Type/Generic/TemplateObjectType.php index ef2c76ef7f..a67aa723dd 100644 --- a/src/Type/Generic/TemplateObjectType.php +++ b/src/Type/Generic/TemplateObjectType.php @@ -13,6 +13,9 @@ final class TemplateObjectType extends ObjectType implements TemplateType /** @use TemplateTypeTrait */ use TemplateTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateObjectWithoutClassType.php b/src/Type/Generic/TemplateObjectWithoutClassType.php index 1f9b0fe0ce..3d3cb9e8ca 100644 --- a/src/Type/Generic/TemplateObjectWithoutClassType.php +++ b/src/Type/Generic/TemplateObjectWithoutClassType.php @@ -13,6 +13,9 @@ class TemplateObjectWithoutClassType extends ObjectWithoutClassType implements T /** @use TemplateTypeTrait */ use TemplateTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateStrictMixedType.php b/src/Type/Generic/TemplateStrictMixedType.php index 8949142920..6ae56cc228 100644 --- a/src/Type/Generic/TemplateStrictMixedType.php +++ b/src/Type/Generic/TemplateStrictMixedType.php @@ -15,6 +15,9 @@ final class TemplateStrictMixedType extends StrictMixedType implements TemplateT /** @use TemplateTypeTrait */ use TemplateTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateStringType.php b/src/Type/Generic/TemplateStringType.php index 17cec7dc55..084612c641 100644 --- a/src/Type/Generic/TemplateStringType.php +++ b/src/Type/Generic/TemplateStringType.php @@ -13,6 +13,9 @@ final class TemplateStringType extends StringType implements TemplateType use TemplateTypeTrait; use UndecidedComparisonCompoundTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/src/Type/Generic/TemplateType.php b/src/Type/Generic/TemplateType.php index 01287c374a..7661078ca1 100644 --- a/src/Type/Generic/TemplateType.php +++ b/src/Type/Generic/TemplateType.php @@ -11,6 +11,7 @@ interface TemplateType extends CompoundType { + /** @return non-empty-string */ public function getName(): string; public function getScope(): TemplateTypeScope; diff --git a/src/Type/Generic/TemplateTypeFactory.php b/src/Type/Generic/TemplateTypeFactory.php index 6d71e1dea5..c29a175d2c 100644 --- a/src/Type/Generic/TemplateTypeFactory.php +++ b/src/Type/Generic/TemplateTypeFactory.php @@ -25,6 +25,9 @@ final class TemplateTypeFactory { + /** + * @param non-empty-string $name + */ public static function create(TemplateTypeScope $scope, string $name, ?Type $bound, TemplateTypeVariance $variance, ?TemplateTypeStrategy $strategy = null): TemplateType { $strategy ??= new TemplateTypeParameterStrategy(); diff --git a/src/Type/Generic/TemplateTypeTrait.php b/src/Type/Generic/TemplateTypeTrait.php index 803ec31348..66fd32a2fd 100644 --- a/src/Type/Generic/TemplateTypeTrait.php +++ b/src/Type/Generic/TemplateTypeTrait.php @@ -25,6 +25,7 @@ trait TemplateTypeTrait { + /** @var non-empty-string */ private string $name; private TemplateTypeScope $scope; @@ -36,6 +37,7 @@ trait TemplateTypeTrait /** @var TBound */ private Type $bound; + /** @return non-empty-string */ public function getName(): string { return $this->name; diff --git a/src/Type/Generic/TemplateUnionType.php b/src/Type/Generic/TemplateUnionType.php index 8e3bf90f5d..997fb21238 100644 --- a/src/Type/Generic/TemplateUnionType.php +++ b/src/Type/Generic/TemplateUnionType.php @@ -11,6 +11,9 @@ final class TemplateUnionType extends UnionType implements TemplateType /** @use TemplateTypeTrait */ use TemplateTypeTrait; + /** + * @param non-empty-string $name + */ public function __construct( TemplateTypeScope $scope, TemplateTypeStrategy $templateTypeStrategy, diff --git a/tests/PHPStan/Reflection/GenericParametersAcceptorResolverTest.php b/tests/PHPStan/Reflection/GenericParametersAcceptorResolverTest.php index 4bcd1d6809..fbc09b872c 100644 --- a/tests/PHPStan/Reflection/GenericParametersAcceptorResolverTest.php +++ b/tests/PHPStan/Reflection/GenericParametersAcceptorResolverTest.php @@ -29,12 +29,15 @@ class GenericParametersAcceptorResolverTest extends PHPStanTestCase */ public function dataResolve(): array { - $templateType = static fn (string $name, ?Type $type = null): Type => TemplateTypeFactory::create( - TemplateTypeScope::createWithFunction('a'), - $name, - $type, - TemplateTypeVariance::createInvariant(), - ); + $templateType = static function (string $name, ?Type $type = null): Type { + /** @var non-empty-string $name */ + return TemplateTypeFactory::create( + TemplateTypeScope::createWithFunction('a'), + $name, + $type, + TemplateTypeVariance::createInvariant(), + ); + }; return [ 'one param, one arg' => [ diff --git a/tests/PHPStan/Type/ArrayTypeTest.php b/tests/PHPStan/Type/ArrayTypeTest.php index ed3af63507..7139878103 100644 --- a/tests/PHPStan/Type/ArrayTypeTest.php +++ b/tests/PHPStan/Type/ArrayTypeTest.php @@ -179,12 +179,15 @@ public function testDescribe( public function dataInferTemplateTypes(): array { - $templateType = static fn (string $name): Type => TemplateTypeFactory::create( - TemplateTypeScope::createWithFunction('a'), - $name, - new MixedType(), - TemplateTypeVariance::createInvariant(), - ); + $templateType = static function (string $name): Type { + /** @var non-empty-string $name */ + return TemplateTypeFactory::create( + TemplateTypeScope::createWithFunction('a'), + $name, + new MixedType(), + TemplateTypeVariance::createInvariant(), + ); + }; return [ 'valid templated item' => [ diff --git a/tests/PHPStan/Type/CallableTypeTest.php b/tests/PHPStan/Type/CallableTypeTest.php index dd5c46acff..f226dae990 100644 --- a/tests/PHPStan/Type/CallableTypeTest.php +++ b/tests/PHPStan/Type/CallableTypeTest.php @@ -177,12 +177,15 @@ public function dataInferTemplateTypes(): array null, ); - $templateType = static fn (string $name): Type => TemplateTypeFactory::create( - TemplateTypeScope::createWithFunction('a'), - $name, - new MixedType(), - TemplateTypeVariance::createInvariant(), - ); + $templateType = static function (string $name): Type { + /** @var non-empty-string $name */ + return TemplateTypeFactory::create( + TemplateTypeScope::createWithFunction('a'), + $name, + new MixedType(), + TemplateTypeVariance::createInvariant(), + ); + }; return [ 'template param' => [ diff --git a/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php b/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php index 049139818e..241b99df48 100644 --- a/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php +++ b/tests/PHPStan/Type/Constant/ConstantArrayTypeTest.php @@ -610,12 +610,15 @@ public function testIsSuperTypeOf(ConstantArrayType $type, Type $otherType, Trin public function dataInferTemplateTypes(): array { - $templateType = static fn (string $name): Type => TemplateTypeFactory::create( - TemplateTypeScope::createWithFunction('a'), - $name, - new MixedType(), - TemplateTypeVariance::createInvariant(), - ); + $templateType = static function (string $name): Type { + /** @var non-empty-string $name */ + return TemplateTypeFactory::create( + TemplateTypeScope::createWithFunction('a'), + $name, + new MixedType(), + TemplateTypeVariance::createInvariant(), + ); + }; return [ 'receive constant array' => [ diff --git a/tests/PHPStan/Type/Generic/GenericObjectTypeTest.php b/tests/PHPStan/Type/Generic/GenericObjectTypeTest.php index 929ec087dc..84c462c247 100644 --- a/tests/PHPStan/Type/Generic/GenericObjectTypeTest.php +++ b/tests/PHPStan/Type/Generic/GenericObjectTypeTest.php @@ -351,12 +351,15 @@ public function testAccepts( /** @return array}> */ public function dataInferTemplateTypes(): array { - $templateType = static fn (string $name, ?Type $bound = null): Type => TemplateTypeFactory::create( - TemplateTypeScope::createWithFunction('a'), - $name, - $bound ?? new MixedType(), - TemplateTypeVariance::createInvariant(), - ); + $templateType = static function (string $name, ?Type $bound = null): Type { + /** @var non-empty-string $name */ + return TemplateTypeFactory::create( + TemplateTypeScope::createWithFunction('a'), + $name, + $bound ?? new MixedType(), + TemplateTypeVariance::createInvariant(), + ); + }; return [ 'simple' => [ @@ -464,12 +467,15 @@ public function testResolveTemplateTypes(Type $received, Type $template, array $ /** @return array}> */ public function dataGetReferencedTypeArguments(): array { - $templateType = static fn (string $name, ?Type $bound = null): TemplateType => TemplateTypeFactory::create( - TemplateTypeScope::createWithFunction('a'), - $name, - $bound ?? new MixedType(), - TemplateTypeVariance::createInvariant(), - ); + $templateType = static function (string $name, ?Type $bound = null): Type { + /** @var non-empty-string $name */ + return TemplateTypeFactory::create( + TemplateTypeScope::createWithFunction('a'), + $name, + $bound ?? new MixedType(), + TemplateTypeVariance::createInvariant(), + ); + }; return [ 'param: Invariant' => [ diff --git a/tests/PHPStan/Type/IterableTypeTest.php b/tests/PHPStan/Type/IterableTypeTest.php index 02a10d0dde..582b1982eb 100644 --- a/tests/PHPStan/Type/IterableTypeTest.php +++ b/tests/PHPStan/Type/IterableTypeTest.php @@ -185,12 +185,15 @@ public function testIsSubTypeOfInversed(IterableType $type, Type $otherType, Tri public function dataInferTemplateTypes(): array { - $templateType = static fn (string $name): Type => TemplateTypeFactory::create( - TemplateTypeScope::createWithFunction('a'), - $name, - new MixedType(), - TemplateTypeVariance::createInvariant(), - ); + $templateType = static function (string $name): Type { + /** @var non-empty-string $name */ + return TemplateTypeFactory::create( + TemplateTypeScope::createWithFunction('a'), + $name, + new MixedType(), + TemplateTypeVariance::createInvariant(), + ); + }; return [ 'receive iterable' => [ diff --git a/tests/PHPStan/Type/TemplateTypeTest.php b/tests/PHPStan/Type/TemplateTypeTest.php index 36281bdba1..37f6953e5b 100644 --- a/tests/PHPStan/Type/TemplateTypeTest.php +++ b/tests/PHPStan/Type/TemplateTypeTest.php @@ -25,12 +25,15 @@ class TemplateTypeTest extends PHPStanTestCase public function dataAccepts(): array { - $templateType = static fn (string $name, ?Type $bound, ?string $functionName = null): Type => TemplateTypeFactory::create( - TemplateTypeScope::createWithFunction($functionName ?? '_'), - $name, - $bound, - TemplateTypeVariance::createInvariant(), - ); + $templateType = static function (string $name, ?Type $bound, ?string $functionName = null): Type { + /** @var non-empty-string $name */ + return TemplateTypeFactory::create( + TemplateTypeScope::createWithFunction($functionName ?? '_'), + $name, + $bound, + TemplateTypeVariance::createInvariant(), + ); + }; return [ 0 => [ @@ -127,12 +130,15 @@ public function testAccepts( public function dataIsSuperTypeOf(): array { - $templateType = static fn (string $name, ?Type $bound, ?string $functionName = null): Type => TemplateTypeFactory::create( - TemplateTypeScope::createWithFunction($functionName ?? '_'), - $name, - $bound, - TemplateTypeVariance::createInvariant(), - ); + $templateType = static function (string $name, ?Type $bound, ?string $functionName = null): Type { + /** @var non-empty-string $name */ + return TemplateTypeFactory::create( + TemplateTypeScope::createWithFunction($functionName ?? '_'), + $name, + $bound, + TemplateTypeVariance::createInvariant(), + ); + }; return [ 0 => [ @@ -315,13 +321,15 @@ public function testIsSuperTypeOf( /** @return array}> */ public function dataInferTemplateTypes(): array { - $templateType = static fn (string $name, ?Type $bound = null, ?string $functionName = null): Type => TemplateTypeFactory::create( - TemplateTypeScope::createWithFunction($functionName ?? '_'), - $name, - $bound, - TemplateTypeVariance::createInvariant(), - ); - + $templateType = static function (string $name, ?Type $bound = null, ?string $functionName = null): Type { + /** @var non-empty-string $name */ + return TemplateTypeFactory::create( + TemplateTypeScope::createWithFunction($functionName ?? '_'), + $name, + $bound, + TemplateTypeVariance::createInvariant(), + ); + }; return [ 'simple' => [ new IntegerType(),