WeaponMasteryLevel::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 11
ccs 10
cts 10
cp 1
rs 9.9666
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Build\Talent\WeaponMastery;
6
7
use AardsGerds\Game\Shared\IntegerValue;
8
use AardsGerds\Game\Shared\IntegerValueException;
9
10
final class WeaponMasteryLevel extends IntegerValue
11
{
12
    public const INEXPERIENCED = 0;
13
    public const NOVICE = 1;
14
    public const WARRIOR = 2;
15
    public const VETERAN = 3;
16
    public const MASTER_OF_FIRST_TIER = 4;
17
    public const MASTER_OF_SECOND_TIER = 5;
18
    public const MASTER_OF_THIRD_TIER = 6;
19
20 3
    public static function inexperienced(): self
21
    {
22 3
        return new self(self::INEXPERIENCED);
23
    }
24
25 5
    public static function novice(): self
26
    {
27 5
        return new self(self::NOVICE);
28
    }
29
30 5
    public static function warrior(): self
31
    {
32 5
        return new self(self::WARRIOR);
33
    }
34
35 3
    public static function veteran(): self
36
    {
37 3
        return new self(self::VETERAN);
38
    }
39
40 5
    public static function masterOfFirstTier(): self
41
    {
42 5
        return new self(self::MASTER_OF_FIRST_TIER);
43
    }
44
45 1
    public static function masterOfSecondTier(): self
46
    {
47 1
        return new self(self::MASTER_OF_SECOND_TIER);
48
    }
49
50 5
    public static function masterOfThirdTier(): self
51
    {
52 5
        return new self(self::MASTER_OF_THIRD_TIER);
53
    }
54
55 7
    public function __toString(): string
56
    {
57 7
        return match ($this->value) {
58 7
            self::INEXPERIENCED => 'inexperienced',
59 6
            self::NOVICE => 'novice',
60 5
            self::WARRIOR => 'warrior',
61 4
            self::VETERAN => 'veteran',
62 3
            self::MASTER_OF_FIRST_TIER => 'master of first tier',
63 2
            self::MASTER_OF_SECOND_TIER => 'master of second tier',
64 1
            self::MASTER_OF_THIRD_TIER => 'master of third tier',
65 7
            default => throw IntegerValueException::invalidValue($this->value),
66
        };
67
    }
68
69 18
    protected function validate(): void
70
    {
71 18
        if (!in_array($this->value, range(self::INEXPERIENCED, self::MASTER_OF_THIRD_TIER))) {
72 1
            throw IntegerValueException::invalidValue($this->value);
73
        }
74 17
    }
75
}
76