| Total Complexity | 8 |
| Total Lines | 92 |
| Duplicated Lines | 0 % |
| Changes | 12 | ||
| Bugs | 4 | Features | 4 |
| 1 | <?php |
||
| 14 | final class Underscore extends UnderscoreFunction |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Constructor. |
||
| 18 | * |
||
| 19 | * @param array|mixed $data |
||
| 20 | */ |
||
| 21 | public function __construct($data = []) |
||
| 22 | { |
||
| 23 | parent::__construct($data); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * A static shortcut to constructor. |
||
| 28 | * |
||
| 29 | * @param array|mixed $data Array or array like or array convertible. |
||
| 30 | * |
||
| 31 | * @return self |
||
| 32 | */ |
||
| 33 | public static function _($data = null) |
||
| 34 | { |
||
| 35 | return new static($data); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Generates a function that always returns a constant value. |
||
| 40 | * |
||
| 41 | * @param mixed $value |
||
| 42 | * |
||
| 43 | * @return callable |
||
| 44 | */ |
||
| 45 | public function constant($value) |
||
| 46 | { |
||
| 47 | return function () use ($value) { |
||
| 48 | return $value; |
||
| 49 | }; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * No operation! |
||
| 54 | * |
||
| 55 | * @return void |
||
| 56 | */ |
||
| 57 | public function noop() |
||
| 58 | { |
||
| 59 | // ;) |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Run callable n times and create new collection. |
||
| 64 | * |
||
| 65 | * @param int $n |
||
| 66 | * @param callable $fn |
||
| 67 | * |
||
| 68 | * @return self |
||
| 69 | */ |
||
| 70 | public function times($n, callable $fn) |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Return a random integer between min and max (inclusive). |
||
| 83 | * |
||
| 84 | * @param int $min |
||
| 85 | * @param int $max |
||
| 86 | * |
||
| 87 | * @return int |
||
| 88 | */ |
||
| 89 | public function random($min, $max) |
||
| 90 | { |
||
| 91 | return \mt_rand($min, $max); |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Generate unique ID (unique for current go/session). |
||
| 96 | * |
||
| 97 | * @param string $prefix |
||
| 98 | * |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | public function uniqueId($prefix = '') |
||
| 106 | } |
||
| 107 | } |
||
| 108 |