DiceHand::getString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
ccs 5
cts 5
cp 1
crap 2
1
<?php
2
3
namespace App\Dice;
4
5
use App\Dice\Dice;
6
7
class DiceHand
8
{
9
    /**
10
     * @var Dice[]
11
     */
12
    private array $hand = [];
13
14 6
    public function add(Dice $die): void
15
    {
16 6
        $this->hand[] = $die;
17
    }
18
19 5
    public function roll(): void
20
    {
21 5
        foreach ($this->hand as $die) {
22 5
            $die->roll();
23
        }
24
    }
25
26 2
    public function getNumberDices(): int
27
    {
28 2
        return count($this->hand);
29
    }
30
31
    /**
32
     * @return array<int|null>
33
     */
34 1
    public function getValues(): array
35
    {
36 1
        $values = [];
37 1
        foreach ($this->hand as $die) {
38 1
            $values[] = $die->getValue();
39
        }
40 1
        return $values;
41
    }
42
43
    /**
44
     * @return int
45
     */
46 1
    public function sum(): int
47
    {
48 1
        $sum = 0;
49 1
        foreach ($this->hand as $die) {
50 1
            $sum += $die->getValue();
51
        }
52 1
        return $sum;
53
    }
54
55
    /**
56
     * @return string[]
57
     */
58 2
    public function getString(): array
59
    {
60 2
        $values = [];
61 2
        foreach ($this->hand as $die) {
62 2
            $values[] = $die->getAsString();
63
        }
64 2
        return $values;
65
    }
66
67
}
68