Skip to content

Commit 596696f

Browse files
authored
ClassReflection: narrow getNativeReflection after isEnum is true
1 parent 7fd5022 commit 596696f

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

build/more-enum-adapter-errors.neon

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Parameter \\#1 \\$expected of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) expects class\\-string\\<ReflectionEnum\\>, string given\\.$#"
5-
count: 1
6-
path: ../tests/PHPStan/Reflection/ClassReflectionTest.php
73
-
84
message: "#^Strict comparison using \\!\\=\\= between class\\-string and 'UnitEnum' will always evaluate to true\\.$#"
95
count: 1
@@ -23,3 +19,6 @@ parameters:
2319
message: "#^Class BackedEnum not found\\.$#"
2420
count: 1
2521
path: ../src/Type/Php/BackedEnumFromMethodDynamicReturnTypeExtension.php
22+
23+
-
24+
message: "#^Call to method PHPStan\\\\Reflection\\\\ClassReflection::isEnum\\(\\) will always evaluate to false\\.$#"

src/Reflection/ClassReflection.php

+1
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ public function isTrait(): bool
716716

717717
/**
718718
* @phpstan-assert-if-true ReflectionEnum $this->reflection
719+
* @phpstan-assert-if-true ReflectionEnum $this->getNativeReflection()
719720
*/
720721
public function isEnum(): bool
721722
{

tests/PHPStan/Reflection/ClassReflectionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public function testEnumIsFinal(): void
296296
$reflectionProvider = $this->createReflectionProvider();
297297
$enum = $reflectionProvider->getClass('PHPStan\Fixture\TestEnum');
298298
$this->assertTrue($enum->isEnum());
299-
$this->assertInstanceOf('ReflectionEnum', $enum->getNativeReflection());
299+
$this->assertInstanceOf('ReflectionEnum', $enum->getNativeReflection()); // @phpstan-ignore-line Exact error differs on PHP 7.4 and others
300300
$this->assertTrue($enum->isFinal());
301301
$this->assertTrue($enum->isFinalByKeyword());
302302
}

0 commit comments

Comments
 (0)