Completed
Push — master ( b902fc...12ea9a )
by Steve
02:16 queued 18s
created

BasicDice   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 24
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
    private $size;
12
13
    public function __construct(int $size)
14
    {
15
        $this->size = $size;
16
    }
17
18
    public function name() : string
19
    {
20
        return "d{$this->size}";
21
    }
22
23
    public function roll()
24
    {
25
        if (! function_exists('random_int')) {
26
            return mt_rand(1, $this->size);
27
        }
28
29
        return random_int(1, $this->size);
30
    }
31
}
32