DiceHand::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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