DiceHand   A
last analyzed

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