File tree Expand file tree Collapse file tree 4 files changed +23
-17
lines changed Expand file tree Collapse file tree 4 files changed +23
-17
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,9 @@ class ReflectionClass
5050 }
5151
5252 /**
53- * @phpstan-assert-if-true class-string<UnitEnum> $this->getName()
53+ * @phpstan-assert-if-true class-string<\UnitEnum> $this->name
54+ * @phpstan-assert-if-true ReflectionClass<\UnitEnum> $this
55+ * @phpstan-assert-if-false !class-string<\UnitEnum> $this->name
5456 */
5557 public function isEnum(): bool
5658 {
Original file line number Diff line number Diff line change @@ -238,6 +238,7 @@ private static function findTestFiles(): iterable
238238 yield __DIR__ . '/../Rules/Methods/data/bug-4801.php ' ;
239239 yield __DIR__ . '/../Rules/Arrays/data/narrow-superglobal.php ' ;
240240 yield __DIR__ . '/../Rules/Methods/data/bug-12927.php ' ;
241+ yield __DIR__ . '/data/reflectionclass-isEnum.php ' ;
241242 }
242243
243244 /**
Original file line number Diff line number Diff line change 22
33namespace EnumReflection81 ;
44
5- use ReflectionClass ;
65use ReflectionEnum ;
7- use ReflectionEnumBackedCase ;
8- use ReflectionEnumUnitCase ;
96use function PHPStan \Testing \assertType ;
107
118enum Foo: int
@@ -22,16 +19,3 @@ function testNarrowGetBackingTypeAfterIsBacked() {
2219 assertType ('ReflectionType ' , $ r ->getBackingType ());
2320 }
2421}
25-
26- function testNarrowClassAfterIsEnum () {
27- /**
28- * @var class-string
29- */
30- $ classString = Foo::class;
31- $ r = new ReflectionClass ($ classString );
32- assertType ('class-string ' , $ classString );
33- if ($ r ->isEnum ()) {
34- assertType ('class-string<\UnitEnum> ' , $ classString );
35- }
36- }
37-
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.1
2+
3+ namespace ReflectionClassIsEnum ;
4+
5+ use ReflectionClass ;
6+ use function PHPStan \Testing \assertType ;
7+
8+ /**
9+ * @param class-string $class
10+ */
11+ function testNarrowClassAfterIsEnum (string $ class ): void {
12+ $ r = new ReflectionClass ($ class );
13+ assertType ('class-string<object> ' , $ r ->name );
14+ if ($ r ->isEnum ()) {
15+ assertType ('ReflectionClass<\UnitEnum> ' , $ r );
16+ assertType ('class-string<\UnitEnum> ' , $ r ->name );
17+ }
18+ }
19+
You can’t perform that action at this time.
0 commit comments