DiceHand::sum()   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 0
Metric Value
cc 2
eloc 4
c 0
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
    private $hand = [];
10
11 1
    public function add(Dice $die): void
12
    {
13 1
        $this->hand[] = $die;
14
    }
15
16 1
    public function roll(): void
17
    {
18 1
        foreach ($this->hand as $die) {
19 1
            $die->roll();
20
        }
21
    }
22
23
    public function getNumberDices(): int
24
    {
25
        return count($this->hand);
26
    }
27
28
    public function getValues(): array
29
    {
30
        $values = [];
31
        foreach ($this->hand as $die) {
32
            $values[] = $die->getValue();
33
        }
34
        return $values;
35
    }
36
37 1
    public function sum(): int
38
    {
39 1
        $sum = 0;
40 1
        foreach ($this->hand as $die) {
41 1
            $sum += $die->getValue();
42
        }
43 1
        return $sum;
44
    }
45
46
    public function getString(): array
47
    {
48
        $values = [];
49
        foreach ($this->hand as $die) {
50
            $values[] = $die->getAsString();
51
        }
52
        return $values;
53
    }
54
}
55