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

BasicDice::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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