Passed
Push — master ( f3a3f5...74a63a )
by Paweł
02:58
created

Corruption   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 53.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
dl 0
loc 31
ccs 8
cts 15
cp 0.5333
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A high() 0 3 1
A low() 0 3 1
A __toString() 0 7 1
A medium() 0 3 1
A validate() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Entity;
6
7
use AardsGerds\Game\Shared\IntegerValue;
8
use AardsGerds\Game\Shared\IntegerValueException;
9
10
final class Corruption extends IntegerValue
11
{
12 2
    public static function low(): self
13
    {
14 2
        return new self(1);
15
    }
16
17 2
    public static function medium(): self
18
    {
19 2
        return new self(2);
20
    }
21
22 4
    public static function high(): self
23
    {
24 4
        return new self(3);
25
    }
26
27
    public function __toString(): string
28
    {
29
        return match ($this->value) {
30
            1 => 'low',
31
            2 => 'medium',
32
            3 => 'high',
33
            default => throw IntegerValueException::invalidValue($this->value),
34
        };
35
    }
36
37 8
    protected function validate(): void
38
    {
39 8
        if (!in_array($this->value, [1, 2, 3])) {
40
            throw IntegerValueException::invalidValue($this->value);
41
        }
42 8
    }
43
}
44