CDice   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 62
rs 10
wmc 5
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A roll() 0 7 2
A getNumOfRolls() 0 4 1
A getResults() 0 4 1
A getTotal() 0 4 1
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