Total Complexity | 12 |
Total Lines | 98 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | class DiceHand |
||
6 | { |
||
7 | /** |
||
8 | * @var array<Dice> Is an array that contains the Dice objects |
||
9 | */ |
||
10 | private array $hand = []; |
||
11 | |||
12 | /** |
||
13 | * addDie. |
||
14 | * |
||
15 | * Add a die to the hand |
||
16 | */ |
||
17 | 7 | public function addDie(Dice $die): void |
|
18 | { |
||
19 | 7 | $this->hand[] = $die; |
|
20 | } |
||
21 | |||
22 | /** |
||
23 | * removeDice. |
||
24 | * |
||
25 | * Remove the top dice from hand |
||
26 | */ |
||
27 | 1 | public function removeDie(): void |
|
28 | { |
||
29 | 1 | if (count($this->hand) > 0) { |
|
30 | 1 | array_shift($this->hand); |
|
31 | } |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * roll. |
||
36 | * |
||
37 | * Roll all the Dice in the hand |
||
38 | */ |
||
39 | 4 | public function roll(): void |
|
40 | { |
||
41 | 4 | foreach ($this->hand as $die) { |
|
42 | 4 | $die->roll(); |
|
43 | } |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * getNumberDices. |
||
48 | * |
||
49 | * Return the number of dice in the hand |
||
50 | */ |
||
51 | 2 | public function getNumberDices(): int |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * getValues. |
||
58 | * |
||
59 | * Return an array of all the Dice values in hand |
||
60 | * |
||
61 | * @return array<int> |
||
62 | */ |
||
63 | 2 | public function getValues(): array |
|
64 | { |
||
65 | 2 | $values = []; |
|
66 | 2 | foreach ($this->hand as $die) { |
|
67 | 2 | $values[] = $die->getValue(); |
|
68 | } |
||
69 | |||
70 | 2 | return $values; |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * sum. |
||
75 | * |
||
76 | * Returns the sum of all Dice values in hand |
||
77 | */ |
||
78 | 1 | public function sum(): int |
|
86 | } |
||
87 | |||
88 | /** |
||
89 | * getString. |
||
90 | * |
||
91 | * Returns an string array containing all the Dice |
||
92 | * |
||
93 | * @return array<string> |
||
94 | */ |
||
95 | 3 | public function getString(): array |
|
103 | } |
||
104 | } |
||
105 |