forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-12798.php
More file actions
50 lines (41 loc) · 1.01 KB
/
bug-12798.php
File metadata and controls
50 lines (41 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php declare(strict_types = 1); // lint >= 8.1
namespace Bug12798;
interface Colorable
{
public function color(): string;
}
trait HasColors
{
/** @return array<string|int, string> */
public static function colors(): array {
return array_reduce(self::cases(), function (array $colors, self $case) {
$key = is_subclass_of($case, \BackedEnum::class) ? $case->value : $case->name;
$color = is_subclass_of($case, Colorable::class) ? $case->color() : 'gray';
$colors[$key] = $color;
$colors[$color] = $color;
return $colors;
}, []);
}
}
enum AlertLevelBacked: int implements Colorable
{
use HasColors;
case Low = 1;
case Medium = 2;
case Critical = 3;
public function color(): string
{
return match ($this) {
self::Low => 'green',
self::Medium => 'yellow',
self::Critical => 'red',
};
}
}
enum AlertLevel
{
use HasColors;
case Low;
case Medium;
case Critical;
}