Passed
Push — master ( a5349e...67d0b1 )
by Stephen
02:28
created

LaravelHelpers::alphabet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
namespace Sfneal\Helpers\Laravel;
5
6
7
use Illuminate\Support\Facades\Cache;
8
use ReflectionClass;
9
use ReflectionException;
10
11
class LaravelHelpers
12
{
13
    /**
14
     * Return the alphabet in array form.
15
     *
16
     * @return array
17
     */
18
    public static function alphabet()
19
    {
20
        return Cache::rememberForever('alphabet', function () {
21
            return range('A', 'Z');
22
        });
23
    }
24
25
    /**
26
     * Return the index of a letter in the alphabet.
27
     *
28
     * @param int $index
29
     * @return string
30
     */
31
    public static function alphabetIndex($index)
32
    {
33
        return self::alphabet()[$index];
34
    }
35
36
    /**
37
     * Retrieve a class's short name (without namespace).
38
     *
39
     * @param $class
40
     * @param bool $short Full name or short name
41
     * @param string|null $default
42
     * @return string
43
     */
44
    public static function getClassName($class, $short = false, $default = null)
45
    {
46
        // Attempt to resolve the $class's name
47
        try {
48
            return (new ReflectionClass($class))->{$short ? 'getShortName' : 'getName'}();
49
        }
50
51
            // Return $default
52
        catch (ReflectionException $e) {
53
            return $default;
54
        }
55
    }
56
57
    /**
58
     * Determine if the Application is running in a 'production' environment.
59
     *
60
     * @return bool
61
     */
62
    public static function isProductionEnvironment()
63
    {
64
        return env('APP_ENV') == 'production';
65
    }
66
67
    /**
68
     * Determine if the Application is running in a 'development' environment.
69
     *
70
     * @return bool
71
     */
72
    public static function isDevelopmentEnvironment()
73
    {
74
        return env('APP_ENV') == 'development';
75
    }
76
77
    /**
78
     * Serialize and simple hash a value to create a unique ID.
79
     *
80
     * @param $value
81
     * @return int
82
     */
83
    public static function serializeHash($value)
84
    {
85
        return crc32(serialize($value));
86
    }
87
}
88