Passed
Pull Request — master (#2027)
by Nico
21:19 queued 10:33
created

SpacecraftAlertStateEnum   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 47.06%

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 35
ccs 8
cts 17
cp 0.4706
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 6 1
A isAtLeast() 0 3 1
A getEpsUsage() 0 6 1
A getRandomAlertLevel() 0 6 1
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
    public function getDescription(): string
14
    {
15
        return match ($this) {
16
            self::ALERT_GREEN => "Alarm Grün",
17
            self::ALERT_YELLOW => "Alarm Gelb",
18
            self::ALERT_RED => "Alarm Rot"
19
        };
20
    }
21
22 7
    public function getEpsUsage(): int
23
    {
24 7
        return match ($this) {
25 7
            self::ALERT_GREEN => 0,
26 4
            self::ALERT_YELLOW => 1,
27 7
            self::ALERT_RED => 2
28 7
        };
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