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

Generator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handler() 0 10 2
A extend() 0 4 1
A generate() 0 4 1
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