Passed
Push — master ( 8387eb...5a11dc )
by Janko
07:59
created

FactionEnum   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 52.94%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 33
ccs 9
cts 17
cp 0.5294
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getColorCode() 0 9 1
A fromName() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Faction;
6
7
use InvalidArgumentException;
8
use RuntimeException;
9
10
enum FactionEnum: int
11
{
12
    case FACTION_FEDERATION = 1;
13
    case FACTION_ROMULAN = 2;
14
    case FACTION_KLINGON = 3;
15
    case FACTION_CARDASSIAN = 4;
16
    case FACTION_FERENGI = 5;
17
    case FACTION_PAKLED = 6;
18
    case FACTION_KAZON = 7;
19
    case FACTION_BORG = 8;
20
    case FACTION_BLANK = 9;
21
22 1
    public function getColorCode(): string
23
    {
24 1
        return match ($this) {
25 1
            self::FACTION_FEDERATION => '#0000ff',
26
            self::FACTION_ROMULAN => '#00ff00',
27
            self::FACTION_KLINGON => '#ff0000',
28
            self::FACTION_CARDASSIAN => '#ff7b42',
29
            self::FACTION_FERENGI => '#943100',
30 1
            default => throw new RuntimeException(sprintf('no color code defined for %s', $this->name))
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Stu\Component\Faction\FactionEnum. Did you maybe forget to declare it?
Loading history...
31 1
        };
32
    }
33
34 3
    public static function fromName(string $name): FactionEnum
35
    {
36 3
        return match ($name) {
37
            'federation' => self::FACTION_FEDERATION,
38
            'romulan' => self::FACTION_ROMULAN,
39 2
            'klingon' => self::FACTION_KLINGON,
40
            'cardassian' => self::FACTION_CARDASSIAN,
41
            'ferengi' => self::FACTION_FERENGI,
42 3
            default => throw new InvalidArgumentException(sprintf('no faction defined for name %s', $name))
43 3
        };
44
    }
45
}
46