From bbebd43bcb68fb67b5e5d901abdd4074e3f374b5 Mon Sep 17 00:00:00 2001 From: Flyingmana Date: Mon, 1 Sep 2025 23:57:36 +0200 Subject: [PATCH 1/3] add missing typehints for Iterators --- .../PHPStan/Type/BenevolentUnionTypeTest.php | 48 +++++++++++++++++++ tests/PHPStan/Type/IntersectionTypeTest.php | 9 ++++ tests/PHPStan/Type/ObjectTypeTest.php | 3 ++ tests/PHPStan/Type/UnionTypeTest.php | 9 ++++ 4 files changed, 69 insertions(+) diff --git a/tests/PHPStan/Type/BenevolentUnionTypeTest.php b/tests/PHPStan/Type/BenevolentUnionTypeTest.php index 0610f74c4f..92ce5521cb 100644 --- a/tests/PHPStan/Type/BenevolentUnionTypeTest.php +++ b/tests/PHPStan/Type/BenevolentUnionTypeTest.php @@ -20,6 +20,9 @@ class BenevolentUnionTypeTest extends PHPStanTestCase { + /** + * @return Iterator + */ public static function dataCanAccessProperties(): Iterator { yield [ @@ -49,6 +52,9 @@ public function testCanAccessProperties(BenevolentUnionType $type, TrinaryLogic ); } + /** + * @return Iterator + */ public static function dataHasProperty(): Iterator { yield [ @@ -87,6 +93,9 @@ public function testHasProperty(BenevolentUnionType $type, string $propertyName, ); } + /** + * @return Iterator + */ public static function dataCanCallMethods(): Iterator { yield [ @@ -116,6 +125,9 @@ public function testCanCanCallMethods(BenevolentUnionType $type, TrinaryLogic $e ); } + /** + * @return Iterator + */ public static function dataHasMethod(): Iterator { yield [ @@ -151,6 +163,9 @@ public function testHasMethod(BenevolentUnionType $type, string $methodName, Tri ); } + /** + * @return Iterator + */ public static function dataCanAccessConstants(): Iterator { yield [ @@ -180,6 +195,9 @@ public function testCanAccessConstants(BenevolentUnionType $type, TrinaryLogic $ ); } + /** + * @return Iterator + */ public static function dataIsIterable(): Iterator { yield [ @@ -215,6 +233,9 @@ public function testIsIterable(BenevolentUnionType $type, TrinaryLogic $expected ); } + /** + * @return Iterator + */ public static function dataIsIterableAtLeastOnce(): Iterator { yield [ @@ -250,6 +271,9 @@ public function testIsIterableAtLeastOnce(BenevolentUnionType $type, TrinaryLogi ); } + /** + * @return Iterator + */ public static function dataIsArray(): Iterator { yield [ @@ -279,6 +303,9 @@ public function testIsArray(BenevolentUnionType $type, TrinaryLogic $expectedRes ); } + /** + * @return Iterator + */ public static function dataIsString(): Iterator { yield [ @@ -311,6 +338,9 @@ public function testIsString(BenevolentUnionType $type, TrinaryLogic $expectedRe ); } + /** + * @return Iterator + */ public static function dataIsNumericString(): Iterator { yield [ @@ -342,6 +372,9 @@ public function testIsNumericString(BenevolentUnionType $type, TrinaryLogic $exp ); } + /** + * @return Iterator + */ public static function dataIsNonFalsyString(): Iterator { yield [ @@ -373,6 +406,9 @@ public function testIsNonFalsyString(BenevolentUnionType $type, TrinaryLogic $ex ); } + /** + * @return Iterator + */ public static function dataIsLiteralString(): Iterator { yield [ @@ -404,6 +440,9 @@ public function testIsLiteralString(BenevolentUnionType $type, TrinaryLogic $exp ); } + /** + * @return Iterator + */ public static function dataIsOffsetAccesible(): Iterator { yield [ @@ -439,6 +478,9 @@ public function testIsOffsetAccessible(BenevolentUnionType $type, TrinaryLogic $ ); } + /** + * @return Iterator + */ public static function dataHasOffsetValueType(): Iterator { yield [ @@ -477,6 +519,9 @@ public function testHasOffsetValue(BenevolentUnionType $type, Type $offsetType, ); } + /** + * @return Iterator + */ public static function dataIsCallable(): Iterator { yield [ @@ -506,6 +551,9 @@ public function testIsCallable(BenevolentUnionType $type, TrinaryLogic $expected ); } + /** + * @return Iterator + */ public static function dataIsCloneable(): Iterator { yield [ diff --git a/tests/PHPStan/Type/IntersectionTypeTest.php b/tests/PHPStan/Type/IntersectionTypeTest.php index 80f6c21b95..679e221782 100644 --- a/tests/PHPStan/Type/IntersectionTypeTest.php +++ b/tests/PHPStan/Type/IntersectionTypeTest.php @@ -28,6 +28,9 @@ class IntersectionTypeTest extends PHPStanTestCase { + /** + * @return Iterator + */ public static function dataAccepts(): Iterator { $intersectionType = new IntersectionType([ @@ -121,6 +124,9 @@ public function testIsCallable(IntersectionType $type, TrinaryLogic $expectedRes ); } + /** + * @return Iterator + */ public static function dataIsSuperTypeOf(): Iterator { $intersectionTypeA = new IntersectionType([ @@ -242,6 +248,9 @@ public function testIsSuperTypeOf(IntersectionType $type, Type $otherType, Trina ); } + /** + * @return Iterator + */ public static function dataIsSubTypeOf(): Iterator { $intersectionTypeA = new IntersectionType([ diff --git a/tests/PHPStan/Type/ObjectTypeTest.php b/tests/PHPStan/Type/ObjectTypeTest.php index 253e9f0c3a..3371c28427 100644 --- a/tests/PHPStan/Type/ObjectTypeTest.php +++ b/tests/PHPStan/Type/ObjectTypeTest.php @@ -557,6 +557,9 @@ public function testAccepts( ); } + /** + * @return Iterator + */ public static function dataHasConstant(): Iterator { yield [ diff --git a/tests/PHPStan/Type/UnionTypeTest.php b/tests/PHPStan/Type/UnionTypeTest.php index c93a5e8d47..ea9bb3ba22 100644 --- a/tests/PHPStan/Type/UnionTypeTest.php +++ b/tests/PHPStan/Type/UnionTypeTest.php @@ -87,6 +87,9 @@ public function testIsCallable(UnionType $type, TrinaryLogic $expectedResult): v ); } + /** + * @return Iterator + */ public static function dataSelfCompare(): Iterator { $reflectionProvider = self::createReflectionProvider(); @@ -166,6 +169,9 @@ public function testSelfCompare(Type $type): void ); } + /** + * @return Iterator + */ public static function dataIsSuperTypeOf(): Iterator { $unionTypeA = new UnionType([ @@ -460,6 +466,9 @@ public function testIsSuperTypeOf(UnionType $type, Type $otherType, TrinaryLogic ); } + /** + * @return Iterator + */ public static function dataIsSubTypeOf(): Iterator { $unionTypeA = new UnionType([ From e5456af7ee010d22dc170e48498a00bc7893e873 Mon Sep 17 00:00:00 2001 From: Flyingmana Date: Tue, 2 Sep 2025 00:16:38 +0200 Subject: [PATCH 2/3] more flexible array-key for Iterator --- tests/PHPStan/Type/UnionTypeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PHPStan/Type/UnionTypeTest.php b/tests/PHPStan/Type/UnionTypeTest.php index ea9bb3ba22..d0ec27f619 100644 --- a/tests/PHPStan/Type/UnionTypeTest.php +++ b/tests/PHPStan/Type/UnionTypeTest.php @@ -170,7 +170,7 @@ public function testSelfCompare(Type $type): void } /** - * @return Iterator + * @return Iterator */ public static function dataIsSuperTypeOf(): Iterator { From 907a4fdde882ba7f80beef3d02a6af7c5ad14f72 Mon Sep 17 00:00:00 2001 From: Flyingmana Date: Tue, 2 Sep 2025 00:22:17 +0200 Subject: [PATCH 3/3] fix code based type missmatch --- tests/PHPStan/Type/IntersectionTypeTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PHPStan/Type/IntersectionTypeTest.php b/tests/PHPStan/Type/IntersectionTypeTest.php index 679e221782..7318ba9c65 100644 --- a/tests/PHPStan/Type/IntersectionTypeTest.php +++ b/tests/PHPStan/Type/IntersectionTypeTest.php @@ -29,7 +29,7 @@ class IntersectionTypeTest extends PHPStanTestCase { /** - * @return Iterator + * @return Iterator */ public static function dataAccepts(): Iterator { @@ -73,7 +73,7 @@ public static function dataAccepts(): Iterator } #[DataProvider('dataAccepts')] - public function testAccepts(IntersectionType $type, Type $otherType, TrinaryLogic $expectedResult): void + public function testAccepts(Type $type, Type $otherType, TrinaryLogic $expectedResult): void { $actualResult = $type->accepts($otherType, true)->result; $this->assertSame(