Passed
Push — main ( da5731...6a4665 )
by Vedrana
04:17
created

DiceHand::getNumberDices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Dice;
4
5
use App\Dice\Dice;
6
7
8
/**
9
 * Class DiceHand
10
 *
11
 * Represents a hand of Dice objects.
12
 */
13
class DiceHand
14
{
15
    /** @var Dice[] Array holding Dice objects in the hand */
16
    private $hand = [];
17
18
    /**
19
     * Add a Dice object to the hand.
20
     *
21
     * @param Dice $die
22
     */
23 5
    public function add(Dice $die): void
24
    {
25 5
        $this->hand[] = $die;
26
    }
27
28
    /**
29
     * Roll all dice in the hand.
30
     */
31 4
    public function roll(): void
32
    {
33 4
        foreach ($this->hand as $die) {
34 4
            $die->roll();
35
        }
36
    }
37
38
    /**
39
     * Get the number of dice in the hand.
40
     *
41
     * @return int The count of dice.
42
     */
43 2
    public function getNumberDices(): int
44
    {
45 2
        return count($this->hand);
46
    }
47
48
    /**
49
     * Get numeric values from all dice in the hand.
50
     *
51
    * @return int[]
52
    */
53 1
    public function getValues(): array
54
    {
55 1
        $values = [];
56 1
        foreach ($this->hand as $die) {
57 1
            $values[] = $die->getValue();
58
        }
59 1
        return $values;
60
    }
61
62
    /**
63
     * Get visual string representations from all dice in the hand.
64
     *
65
    * @return string[]
66
    */
67 3
    public function getString(): array
68
    {
69 3
        $values = [];
70 3
        foreach ($this->hand as $die) {
71 3
            $values[] = $die->getAsString();
72
        }
73 3
        return $values;
74
    }
75
}
76