BasicDice   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 26
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A name() 0 4 1
A roll() 0 8 2
1
<?php
2
3
4
namespace MeadSteve\DiceApi\Dice;
5
6
use MeadSteve\DiceApi\Dice;
7
8
class BasicDice implements Dice
9
{
10
    /**
11
     * @var int
12
     */
13
    private $size;
14
15
    public function __construct(int $size)
16
    {
17
        $this->size = $size;
18
    }
19
20
    public function name() : string
21
    {
22
        return "d{$this->size}";
23
    }
24
25
    public function roll(): int
26
    {
27
        if (! function_exists('random_int')) {
28
            return mt_rand(1, $this->size);
29
        }
30
31
        return random_int(1, $this->size);
32
    }
33
}
34