CDice::getTotal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Mos\Dice;
4
5
/**
6
 * A CDice class to play around with a dice.
7
 *
8
 */
9
class CDice
10
{
11
12
    /**
13
    * Properties
14
    *
15
    */
16
    private $lastRoll = [];
17
18
19
20
    /**
21
     * Roll the dice
22
     *
23
     * @param int $times the number of times to roll.
24
     * 
25
     * @return void
26
     */
27
    public function roll($times) 
28
    {
29
        $this->lastRoll = array();
30
        for ($i = 0; $i < $times; $i++) {
31
              $this->lastRoll[] = rand(1, 6);
32
        }
33
    }
34
35
36
37
    /**
38
     * Get number of rolls in last roll
39
     *
40
     * @return int
41
     */
42
    public function getNumOfRolls() 
43
    {
44
        return count($this->lastRoll);
45
    }
46
47
48
49
    /**
50
     * Get the array that contains the last roll(s).
51
     *
52
     * @return void
53
     */
54
    public function getResults() 
55
    {
56
        return $this->lastRoll;
57
    }
58
59
60
61
    /**
62
     * Get the total from the last roll(s).
63
     *
64
     * @return void
65
     */
66
    public function getTotal() 
67
    {
68
        return array_sum($this->lastRoll);
69
    }
70
}
71