Underscore::noop()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the PHP-UNDERSCORE package.
5
 *
6
 * (c) Jitendra Adhikari <[email protected]>
7
 *     <https://github.com/adhocore>
8
 *
9
 * Licensed under MIT license.
10
 */
11
12
namespace Ahc\Underscore;
13
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)
71
    {
72
        $data = [];
73
74
        for ($i = 0; $i < $n; $i++) {
75
            $data[$i] = $fn($i);
76
        }
77
78
        return new static($data);
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 = '')
102
    {
103
        static $id = 0;
104
105
        return $prefix . (++$id);
106
    }
107
}
108