Random   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 10 2
A set_queue() 0 3 1
A clear_queue() 0 3 1
A queue_up() 0 7 1
A queue_min() 0 5 1
A queue_max() 0 5 1
1
<?php
2
3
namespace DiceCalc;
4
5
/**
6
 * Class Random
7
 *
8
 * @package DiceCalc
9
 * @author  Owen Winkler <[email protected]>
10
 * @license MIT http://opensource.org/licenses/MIT
11
 */
12
class Random {
13
    public static $queue = null;
14
    public static $queue_list = [];
15
16
    public static function get($min, $max) {
17
        if(is_callable(self::$queue)) {
18
            $test_fn = self::$queue;
19
            $result = $test_fn($min, $max);
20
        }
21
        else {
22
            $result = mt_rand($min, $max);
23
        }
24
        return $result;
25
    }
26
27
    public static function set_queue($queue) {
28
        self::$queue = $queue;
29
    }
30
31
    public static function clear_queue() {
32
        self::$queue = null;
33
    }
34
35
    public static function queue_up() {
36
        $numbers = func_get_args();
37
        self::$queue_list = self::$queue_list + $numbers;
38
        self::set_queue(function($min, $max){
0 ignored issues
show
Unused Code introduced by
The parameter $min is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $max is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
                return array_shift(self::$queue_list);
40
            });
41
    }
42
43
    public static function queue_min() {
44
        self::set_queue(function($min, $max) {
0 ignored issues
show
Unused Code introduced by
The parameter $max is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
            return $min;
46
        });
47
    }
48
49
    public static function queue_max() {
50
        self::set_queue(function($min, $max) {
51
            return $max;
52
        });
53
    }
54
}