WeaponMasteryLevel   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
eloc 26
c 2
b 0
f 0
dl 0
loc 63
ccs 27
cts 27
cp 1
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A veteran() 0 3 1
A masterOfFirstTier() 0 3 1
A novice() 0 3 1
A validate() 0 4 2
A warrior() 0 3 1
A masterOfSecondTier() 0 3 1
A __toString() 0 11 1
A masterOfThirdTier() 0 3 1
A inexperienced() 0 3 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