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

DiceHand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 61
ccs 17
cts 17
cp 1
rs 10
wmc 8

5 Methods

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