Total Complexity | 5 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
22 | abstract class AbstractState implements PossibleStates, RepresentableAsText |
||
23 | { |
||
24 | |||
25 | private $state; |
||
26 | |||
27 | 3 | public function __construct(int $state) |
|
28 | { |
||
29 | 3 | $this->setState($state); |
|
30 | 2 | } |
|
31 | |||
32 | /** |
||
33 | * Implements a method from the PossibleState interface. |
||
34 | * @see PossibleState::isValidValue($state) |
||
35 | */ |
||
36 | 3 | final public function checkValidity(int $state): void |
|
37 | { |
||
38 | 3 | Assert::keyExists($this->getAllExisting(), $state); |
|
39 | 2 | } |
|
40 | |||
41 | /** |
||
42 | * @see PossibleState::getAllExisting() |
||
43 | */ |
||
44 | abstract public function getAllExisting(): array; |
||
45 | |||
46 | /** |
||
47 | * Implements a method from the PossibleState interface. |
||
48 | * @see PossibleState::isValidValue() |
||
49 | */ |
||
50 | 1 | final public function getTextValue(): string |
|
51 | { |
||
52 | 1 | return $this->getAllExisting()[$this->state]; |
|
53 | } |
||
54 | |||
55 | /** |
||
56 | * Returns the state value in a numeric form. |
||
57 | * @return int |
||
58 | */ |
||
59 | 2 | public function getState():int |
|
62 | } |
||
63 | |||
64 | 3 | final protected function setState(int $state) |
|
68 | 2 | } |
|
69 | |||
71 |