From e745b79866ae9b9956cd4f7c4424b5243ad9293c Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Tue, 8 Apr 2025 12:45:25 +0200 Subject: [PATCH 1/4] ClassReflection: narrow getNativeReflection after isEnum is true --- src/Reflection/ClassReflection.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Reflection/ClassReflection.php b/src/Reflection/ClassReflection.php index 05a9f9b6a6..965e6a5478 100644 --- a/src/Reflection/ClassReflection.php +++ b/src/Reflection/ClassReflection.php @@ -714,6 +714,7 @@ public function isTrait(): bool /** * @phpstan-assert-if-true ReflectionEnum $this->reflection + * @phpstan-assert-if-true ReflectionEnum $this->getNativeReflection() */ public function isEnum(): bool { From db8a714e5808a12dba3271dcf70297daf0f933cb Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Tue, 8 Apr 2025 12:52:23 +0200 Subject: [PATCH 2/4] Ignore in test --- tests/PHPStan/Reflection/ClassReflectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PHPStan/Reflection/ClassReflectionTest.php b/tests/PHPStan/Reflection/ClassReflectionTest.php index 7058b8b510..c886685864 100644 --- a/tests/PHPStan/Reflection/ClassReflectionTest.php +++ b/tests/PHPStan/Reflection/ClassReflectionTest.php @@ -296,7 +296,7 @@ public function testEnumIsFinal(): void $reflectionProvider = $this->createReflectionProvider(); $enum = $reflectionProvider->getClass('PHPStan\Fixture\TestEnum'); $this->assertTrue($enum->isEnum()); - $this->assertInstanceOf('ReflectionEnum', $enum->getNativeReflection()); + $this->assertInstanceOf('ReflectionEnum', $enum->getNativeReflection()); // @phpstan-ignore method.alreadyNarrowedType $this->assertTrue($enum->isFinal()); $this->assertTrue($enum->isFinalByKeyword()); } From 8e5ddce7aad76bd85af04c01936659e8a7e897e2 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Tue, 15 Apr 2025 15:58:35 +0200 Subject: [PATCH 3/4] Try fix CI on PHP 7.4 --- build/more-enum-adapter-errors.neon | 3 +++ tests/PHPStan/Reflection/ClassReflectionTest.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build/more-enum-adapter-errors.neon b/build/more-enum-adapter-errors.neon index 69882bcfc5..3aecfcd664 100644 --- a/build/more-enum-adapter-errors.neon +++ b/build/more-enum-adapter-errors.neon @@ -23,3 +23,6 @@ parameters: message: "#^Class BackedEnum not found\\.$#" count: 1 path: ../src/Type/Php/BackedEnumFromMethodDynamicReturnTypeExtension.php + + - + message: "#^Call to method PHPStan\\\\Reflection\\\\ClassReflection::isEnum\\(\\) will always evaluate to false\\.$#" diff --git a/tests/PHPStan/Reflection/ClassReflectionTest.php b/tests/PHPStan/Reflection/ClassReflectionTest.php index c886685864..0e9cec5569 100644 --- a/tests/PHPStan/Reflection/ClassReflectionTest.php +++ b/tests/PHPStan/Reflection/ClassReflectionTest.php @@ -296,7 +296,7 @@ public function testEnumIsFinal(): void $reflectionProvider = $this->createReflectionProvider(); $enum = $reflectionProvider->getClass('PHPStan\Fixture\TestEnum'); $this->assertTrue($enum->isEnum()); - $this->assertInstanceOf('ReflectionEnum', $enum->getNativeReflection()); // @phpstan-ignore method.alreadyNarrowedType + $this->assertInstanceOf('ReflectionEnum', $enum->getNativeReflection()); // @phpstan-ignore-line $this->assertTrue($enum->isFinal()); $this->assertTrue($enum->isFinalByKeyword()); } From 79f5069dd3d789f4e47ee95bf9b5d6db3e0fb1e3 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Tue, 15 Apr 2025 16:06:15 +0200 Subject: [PATCH 4/4] Final? fixes --- build/more-enum-adapter-errors.neon | 4 ---- tests/PHPStan/Reflection/ClassReflectionTest.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/build/more-enum-adapter-errors.neon b/build/more-enum-adapter-errors.neon index 3aecfcd664..4e7e2ee083 100644 --- a/build/more-enum-adapter-errors.neon +++ b/build/more-enum-adapter-errors.neon @@ -1,9 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Parameter \\#1 \\$expected of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) expects class\\-string\\, string given\\.$#" - count: 1 - path: ../tests/PHPStan/Reflection/ClassReflectionTest.php - message: "#^Strict comparison using \\!\\=\\= between class\\-string and 'UnitEnum' will always evaluate to true\\.$#" count: 1 diff --git a/tests/PHPStan/Reflection/ClassReflectionTest.php b/tests/PHPStan/Reflection/ClassReflectionTest.php index 0e9cec5569..b4d2fa5eb4 100644 --- a/tests/PHPStan/Reflection/ClassReflectionTest.php +++ b/tests/PHPStan/Reflection/ClassReflectionTest.php @@ -296,7 +296,7 @@ public function testEnumIsFinal(): void $reflectionProvider = $this->createReflectionProvider(); $enum = $reflectionProvider->getClass('PHPStan\Fixture\TestEnum'); $this->assertTrue($enum->isEnum()); - $this->assertInstanceOf('ReflectionEnum', $enum->getNativeReflection()); // @phpstan-ignore-line + $this->assertInstanceOf('ReflectionEnum', $enum->getNativeReflection()); // @phpstan-ignore-line Exact error differs on PHP 7.4 and others $this->assertTrue($enum->isFinal()); $this->assertTrue($enum->isFinalByKeyword()); }