Passed
Push — master ( 8183fa...32f922 )
by Paweł
11:33
created

Ascension::getRequiredEtherum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 12
ccs 11
cts 11
cp 1
rs 9.9332
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AardsGerds\Game\Build\Talent\SecretKnowledge;
6
7
use AardsGerds\Game\Build\Attribute\Etherum;
8
use AardsGerds\Game\Shared\IntegerValue;
9
use AardsGerds\Game\Shared\IntegerValueException;
10
11
final class Ascension extends IntegerValue
12
{
13
    public const FIRST_ASCENSION = 1;
14
    public const SECOND_ASCENSION = 2;
15
    public const THIRD_ASCENSION = 3;
16
    public const FOURTH_ASCENSION = 4;
17
    public const FIFTH_ASCENSION = 5;
18
    public const SIXTH_ASCENSION = 6;
19
    public const SEVENTH_ASCENSION = 7;
20
    public const EIGHTH_ASCENSION = 8;
21
22 1
    public static function firstAscension(): self
23
    {
24 1
        return new self(self::FIRST_ASCENSION);
25
    }
26
27 1
    public static function secondAscension(): self
28
    {
29 1
        return new self(self::SECOND_ASCENSION);
30
    }
31
32 1
    public static function thirdAscension(): self
33
    {
34 1
        return new self(self::THIRD_ASCENSION);
35
    }
36
37 1
    public static function fourthAscension(): self
38
    {
39 1
        return new self(self::FOURTH_ASCENSION);
40
    }
41
42 1
    public static function fifthAscension(): self
43
    {
44 1
        return new self(self::FIFTH_ASCENSION);
45
    }
46
47 1
    public static function sixthAscension(): self
48
    {
49 1
        return new self(self::SIXTH_ASCENSION);
50
    }
51
52 1
    public static function seventhAscension(): self
53
    {
54 1
        return new self(self::SEVENTH_ASCENSION);
55
    }
56
57 1
    public static function eighthAscension(): self
58
    {
59 1
        return new self(self::EIGHTH_ASCENSION);
60
    }
61
62 8
    public function getRequiredEtherum(): Etherum
63
    {
64 8
        return match ($this->value) {
65 8
            self::FIRST_ASCENSION => new Etherum(10),
66 7
            self::SECOND_ASCENSION => new Etherum(20),
67 6
            self::THIRD_ASCENSION => new Etherum(40),
68 5
            self::FOURTH_ASCENSION => new Etherum(80),
69 4
            self::FIFTH_ASCENSION => new Etherum(160),
70 3
            self::SIXTH_ASCENSION => new Etherum(320),
71 2
            self::SEVENTH_ASCENSION => new Etherum(640),
72 1
            self::EIGHTH_ASCENSION => new Etherum(1280),
73 8
            default => throw IntegerValueException::invalidValue($this->value),
74
        };
75
    }
76
77 8
    public function __toString(): string
78
    {
79 8
        return match ($this->value) {
80 8
            self::FIRST_ASCENSION => 'First Ascension',
81 7
            self::SECOND_ASCENSION => 'Second Ascension',
82 6
            self::THIRD_ASCENSION => 'Third Ascension',
83 5
            self::FOURTH_ASCENSION => 'Fourth Ascension',
84 4
            self::FIFTH_ASCENSION => 'Fifth Ascension',
85 3
            self::SIXTH_ASCENSION => 'Sixth Ascension',
86 2
            self::SEVENTH_ASCENSION => 'Seventh Ascension',
87 1
            self::EIGHTH_ASCENSION => 'Eighth Ascension',
88 8
            default => throw IntegerValueException::invalidValue($this->value),
89
        };
90
    }
91
92 9
    protected function validate(): void
93
    {
94 9
        if (!in_array($this->value, range(self::FIRST_ASCENSION, self::EIGHTH_ASCENSION))) {
95 1
            throw IntegerValueException::invalidValue($this->value);
96
        }
97 8
    }
98
}
99