Dice   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 46
ccs 9
cts 9
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getString() 0 3 1
A roll() 0 5 1
A getValue() 0 3 1
1
<?php
2
3
namespace App\Dice;
4
5
class Dice
6
{
7
    protected int $value;
8
9
    /**
10
     * __construct.
11
     *
12
     * Constructor of the class
13
     *
14
     * @return void
15
     */
16 10
    public function __construct()
17
    {
18 10
        $this->value = random_int(1, 6);
19
    }
20
21
    /**
22
     * roll.
23
     *
24
     * Roll a new value for the dice (1-6)
25
     */
26 7
    public function roll(): int
27
    {
28 7
        $this->value = random_int(1, 6);
29
30 7
        return $this->value;
31
    }
32
33
    /**
34
     * getValue.
35
     *
36
     * Returns the value of the dice
37
     */
38 2
    public function getValue(): int
39
    {
40 2
        return $this->value;
41
    }
42
43
    /**
44
     * getString.
45
     *
46
     * Returns the value of the dice as a string
47
     */
48 2
    public function getString(): string
49
    {
50 2
        return "[{$this->value}]";
51
    }
52
}
53