Passed
Push — master ( 2de9e3...c87c14 )
by Janko
09:57
created

SpacecraftAlertStateEnum::getRandomAlertLevel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Spacecraft;
6
7
enum SpacecraftAlertStateEnum: int
8
{
9
    case ALERT_GREEN = 1;
10
    case ALERT_YELLOW = 2;
11
    case ALERT_RED = 3;
12
13 1
    public function getDescription(): string
14
    {
15 1
        return match ($this) {
16 1
            self::ALERT_GREEN => "Alarm Grün",
17 1
            self::ALERT_YELLOW => "Alarm Gelb",
18 1
            self::ALERT_RED => "Alarm Rot"
19 1
        };
20
    }
21
22 8
    public function getEpsUsage(): int
23
    {
24 8
        return match ($this) {
25 8
            self::ALERT_GREEN => 0,
26 8
            self::ALERT_YELLOW => 1,
27 8
            self::ALERT_RED => 2
28 8
        };
29
    }
30
31 1
    public function isAtLeast(SpacecraftAlertStateEnum $minimum): bool
32
    {
33 1
        return $this->value >= $minimum->value;
34
    }
35
36
    public static function getRandomAlertLevel(): SpacecraftAlertStateEnum
37
    {
38
        /** @var array<int> */
39
        $values = array_map(fn(SpacecraftAlertStateEnum $alertState) => $alertState->value, self::cases());
40
41
        return self::from($values[array_rand($values)]);
42
    }
43
}
44