-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,23 @@ class ReflectionClass | |
{ | ||
} | ||
} | ||
|
||
/** | ||
* @template-covariant T of UnitEnum | ||
* @extends ReflectionClass<T> | ||
*/ | ||
class ReflectionEnum extends ReflectionClass | ||
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Compiler Tests
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Compiler Tests
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, windows-latest)
Check failure on line 56 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, windows-latest)
|
||
{ | ||
|
||
/** | ||
* @return (T is BackedEnum ? ReflectionEnumBackedCase[] : ReflectionEnumUnitCase[]) | ||
*/ | ||
public function getCases(): array {} | ||
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Compiler Tests
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Compiler Tests
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Compiler Tests
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Compiler Tests
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, windows-latest)
Check failure on line 62 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, windows-latest)
|
||
|
||
/** | ||
* @return (T is BackedEnum ? ReflectionEnumBackedCase : ReflectionEnumUnitCase) | ||
* @throws ReflectionException If no found single reflection object for the corresponding case | ||
*/ | ||
public function getCase(string $name): ReflectionEnumUnitCase {} | ||
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Compiler Tests
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Compiler Tests
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Compiler Tests
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Compiler Tests
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (8.0, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests with old PHPUnit (7.2, ubuntu-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.3, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.4, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.4, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (8.0, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / Tests (7.3, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, windows-latest)
Check failure on line 68 in stubs/ReflectionClass.stub GitHub Actions / PHPStan (7.2, windows-latest)
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php // lint >= 8.1 | ||
|
||
namespace EnumReflection; | ||
|
||
use ReflectionEnum; | ||
use ReflectionEnumBackedCase; | ||
use ReflectionEnumUnitCase; | ||
use function PHPStan\Testing\assertType; | ||
|
||
enum Foo: int | ||
{ | ||
|
||
case FOO = 1; | ||
case BAR = 2; | ||
|
||
public function doFoo(): void | ||
{ | ||
$r = new ReflectionEnum(self::class); | ||
foreach ($r->getCases() as $case) { | ||
assertType(ReflectionEnumBackedCase::class, $case); | ||
} | ||
|
||
assertType(ReflectionEnumBackedCase::class, $r->getCase('FOO')); | ||
} | ||
|
||
} | ||
|
||
enum Bar | ||
{ | ||
|
||
case FOO; | ||
case BAR; | ||
|
||
public function doFoo(): void | ||
{ | ||
$r = new ReflectionEnum(self::class); | ||
foreach ($r->getCases() as $case) { | ||
assertType(ReflectionEnumUnitCase::class, $case); | ||
} | ||
assertType(ReflectionEnumUnitCase::class, $r->getCase('FOO')); | ||
} | ||
|
||
} |