Generator   A
last analyzed

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