Skip to content

Commit

Permalink
More precise UnitEnum::cases() return type
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 26, 2024
1 parent 4b95914 commit 32f351a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions resources/functionMap_php81delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'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'],
'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'],
'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}>'],
'UnitEnum::cases' => ['list<static>'],
],
'old' => [
'pg_escape_bytea' => ['string', 'connection'=>'resource', 'data'=>'string'],
Expand Down
2 changes: 1 addition & 1 deletion stubs/runtime/Enum/UnitEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
interface UnitEnum
{
/**
* @return static[]
* @return list<static>
*/
public static function cases(): array;
}
Expand Down
30 changes: 30 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-11233.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php // lint >= 8.1

namespace Bug11233;

use function PHPStan\Testing\assertType;

class EnumExtension
{
/**
* @template T of \UnitEnum
*
* @param class-string<T> $enum
*/
public static function getEnumCases(string $enum): void
{
assertType('list<T of UnitEnum (method Bug11233\EnumExtension::getEnumCases(), argument)>', $enum::cases());
}

/**
* @template T of \BackedEnum
*
* @param class-string<T> $enum
*
* @return list<T>
*/
public static function getEnumCases2(string $enum): void
{
assertType('list<T of BackedEnum (method Bug11233\EnumExtension::getEnumCases2(), argument)>', $enum::cases());
}
}
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/nsrt/bug-7162.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum Test{
* @phpstan-param TEnum $case
*/
function dumpCases(\UnitEnum $case) : void{
assertType('array<TEnum of UnitEnum (function Bug7162\\dumpCases(), argument)>', $case::cases());
assertType('list<TEnum of UnitEnum (function Bug7162\\dumpCases(), argument)>', $case::cases());
}

function dumpCases2(Test $case) : void{
Expand Down

0 comments on commit 32f351a

Please sign in to comment.