DiceHand   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 58
rs 10
ccs 22
cts 22
cp 1
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getNumberDices() 0 3 1
A roll() 0 4 2
A sum() 0 7 2
A getString() 0 7 2
A getValues() 0 7 2
A add() 0 3 1
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