Completed
Push — master ( 00502f...bef3d5 )
by Steve
03:34
created

BasicDice   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 0
dl 0
loc 24
rs 10

3 Methods

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