File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
tests/PHPStan/Analyser/nsrt Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.1
2+
3+ namespace Bug13782 ;
4+
5+ use BackedEnum ;
6+ use function PHPStan \Testing \assertType ;
7+
8+ enum IntEnum : int
9+ {
10+ case A = 1 ;
11+ case B = 2 ;
12+ }
13+
14+ class EnumMethods
15+ {
16+ /**
17+ * @template TEnum of BackedEnum
18+ * @param TEnum $enum
19+ * @return value-of<TEnum>
20+ */
21+ public static function getValue (BackedEnum $ enum ): int |string
22+ {
23+ return $ enum ->value ;
24+ }
25+
26+ /**
27+ * @template TEnum of BackedEnum
28+ * @param TEnum|null $enum
29+ * @return ($enum is TEnum ? value-of<TEnum> : null)
30+ */
31+ public static function getNullableValue (?BackedEnum $ enum ): int |string |null
32+ {
33+ return $ enum === null ? null : $ enum ->value ;
34+ }
35+ }
36+
37+ assertType ("2 " , EnumMethods::getValue (IntEnum::B));
38+ assertType ("2 " , EnumMethods::getNullableValue (IntEnum::B));
You can’t perform that action at this time.
0 commit comments