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

Corruption::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.1481

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 0
crap 2.1481
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