DiceHand   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 45.45%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 46
rs 10
ccs 10
cts 22
cp 0.4545
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
    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