Completed
Push — master ( 756a2d...ed49ca )
by Sercan
01:19
created

Generator::generate()   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 0
1
<?php
2
3
namespace Mayoz\Token;
4
5
use InvalidArgumentException;
6
7
class Generator
8
{
9
    /**
10
     * The token generator function.
11
     *
12
     * @var callable
13
     */
14
    protected static $handler;
15
16
    /**
17
     * Get the callback function.
18
     *
19
     * @return callable
20
     */
21
    public static function handler()
22
    {
23
        if (is_null(static::$handler)) {
24
            static::$handler = function () {
25
                return str_random(36);
26
            };
27
        }
28
29
        return static::$handler;
30
    }
31
32
    /**
33
     * Register a custom generator handler.
34
     *
35
     * @param  callable  $handler
36
     * @return void
37
     */
38
    public static function extend(callable $handler)
39
    {
40
        static::$handler = $handler;
41
    }
42
43
    /**
44
     * Generate a new token value.
45
     *
46
     * @return string
47
     */
48
    public static function generate()
49
    {
50
        return value(static::handler());
51
    }
52
}
53