Random::queue_up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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
}