Skip to content

Commit 32f351a

Browse files
committed
More precise UnitEnum::cases() return type
1 parent 4b95914 commit 32f351a

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

resources/functionMap_php81delta.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'mysqli_result::fetch_field' => ['(stdClass&object{name: string, orgname: string, table: string, orgtable: string, def: string, db: string, catalog: "def", max_length: 0, length: int, charsetnr: string, flags: int, type: int, decimals: int})|false'],
2828
'mysqli_result::fetch_field_direct' => ['(stdClass&object{name: string, orgname: string, table: string, orgtable: string, def: string, db: string, catalog: "def", max_length: 0, length: int, charsetnr: string, flags: int, type: int, decimals: int})|false', 'fieldnr'=>'int'],
2929
'mysqli_result::fetch_fields' => ['list<stdClass&object{name: string, orgname: string, table: string, orgtable: string, def: string, db: string, catalog: "def", max_length: 0, length: int, charsetnr: string, flags: int, type: int, decimals: int}>'],
30+
'UnitEnum::cases' => ['list<static>'],
3031
],
3132
'old' => [
3233
'pg_escape_bytea' => ['string', 'connection'=>'resource', 'data'=>'string'],

stubs/runtime/Enum/UnitEnum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
interface UnitEnum
99
{
1010
/**
11-
* @return static[]
11+
* @return list<static>
1212
*/
1313
public static function cases(): array;
1414
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php // lint >= 8.1
2+
3+
namespace Bug11233;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class EnumExtension
8+
{
9+
/**
10+
* @template T of \UnitEnum
11+
*
12+
* @param class-string<T> $enum
13+
*/
14+
public static function getEnumCases(string $enum): void
15+
{
16+
assertType('list<T of UnitEnum (method Bug11233\EnumExtension::getEnumCases(), argument)>', $enum::cases());
17+
}
18+
19+
/**
20+
* @template T of \BackedEnum
21+
*
22+
* @param class-string<T> $enum
23+
*
24+
* @return list<T>
25+
*/
26+
public static function getEnumCases2(string $enum): void
27+
{
28+
assertType('list<T of BackedEnum (method Bug11233\EnumExtension::getEnumCases2(), argument)>', $enum::cases());
29+
}
30+
}

tests/PHPStan/Analyser/nsrt/bug-7162.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ enum Test{
2929
* @phpstan-param TEnum $case
3030
*/
3131
function dumpCases(\UnitEnum $case) : void{
32-
assertType('array<TEnum of UnitEnum (function Bug7162\\dumpCases(), argument)>', $case::cases());
32+
assertType('list<TEnum of UnitEnum (function Bug7162\\dumpCases(), argument)>', $case::cases());
3333
}
3434

3535
function dumpCases2(Test $case) : void{

0 commit comments

Comments
 (0)