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

Corruption::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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