Completed
Push — master ( 204ad0...5e0009 )
by Nasrul Hazim
02:26
created

minify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 17
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 24
rs 9.7
1
<?php
2
3
use Illuminate\Support\Str;
4
5
/*
6
 * generate sequence
7
 * @return sequence based on length supplied
8
 */
9
if (! function_exists('generate_sequence')) {
10
    function generate_sequence($input = 1)
11
    {
12
        return str_pad($input, config('helper.sequence_length'), '0', STR_PAD_LEFT);
13
    }
14
}
15
16
/*
17
 * Get Abbreviation fo the given text
18
 */
19
if (! function_exists('abbrv')) {
20
    function abbrv($value, $unique_characters = true)
21
    {
22
        if (true === config('helper.abbrv.remove_non_alphanumeric')) {
23
            $value = preg_replace('/[^A-Za-z0-9 ]/', '', $value);
24
        }
25
26
        $value = str_replace(
27
            config('helper.abbrv.remove_vowels'),
28
            '',
29
            $value);
30
31
        if (true === config('helper.abbrv.to_uppercase')) {
32
            $value = strtoupper($value);
33
        }
34
35
        if (true == config('helper.abbrv.unique_characters') || true == $unique_characters) {
36
            $split             = str_split($value);
37
            $unique_characters = [];
38
            foreach ($split as $character) {
39
                if (! in_array($character, $unique_characters)) {
40
                    $unique_characters[] = $character;
41
                }
42
            }
43
44
            return implode('', $unique_characters);
45
        }
46
47
        return $value;
48
    }
49
}
50
51
/*
52
 * Get Fully Qualified Class Name (FQCN) for an Object
53
 */
54
if (! function_exists('fqcn')) {
55
    function fqcn($object)
56
    {
57
        return get_class($object);
58
    }
59
}
60
61
/*
62
 * Get Slug Name for Fully Qualified Class Name (FQCN)
63
 */
64
if (! function_exists('str_slug_fqcn')) {
65
    function str_slug_fqcn($object)
66
    {
67
        return Str::kebab(fqcn($object));
68
    }
69
}
70
71
/*
72
 * Send Notification To User
73
 */
74
if (! function_exists('notify')) {
75
    function notify($identifier, $column = 'id')
76
    {
77
        return \CleaniqueCoders\LaravelHelper\Services\NotificationService::make($identifier, $column);
0 ignored issues
show
Unused Code introduced by
The call to CleaniqueCoders\LaravelH...ficationService::make() has too many arguments starting with $column. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
        return \CleaniqueCoders\LaravelHelper\Services\NotificationService::/** @scrutinizer ignore-call */ make($identifier, $column);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
78
    }
79
}
80
81
/*
82
 * user() helper
83
 */
84
if (! function_exists('user')) {
85
    function user()
86
    {
87
        foreach (config('auth.guards') as $key => $value) {
88
            if (Auth::guard($key)->check()) {
89
                return Auth::guard($key)->user();
90
            }
91
        }
92
93
        return null;
94
    }
95
}
96
97
/*
98
 * Minify given HTML Content
99
 */
100
if (! function_exists('minify')) {
101
    function minify($value)
102
    {
103
        $replace = [
104
            '/<!--[^\[](.*?)[^\]]-->/s' => '',
105
            "/<\?php/"                  => '<?php ',
106
            "/\n([\S])/"                => '$1',
107
            "/\r/"                      => '',
108
            "/\n/"                      => '',
109
            "/\t/"                      => '',
110
            '/ +/'                      => ' ',
111
        ];
112
113
        if (false !== strpos($value, '<pre>')) {
114
            $replace = [
115
                '/<!--[^\[](.*?)[^\]]-->/s' => '',
116
                "/<\?php/"                  => '<?php ',
117
                "/\r/"                      => '',
118
                "/>\n</"                    => '><',
119
                "/>\s+\n</"                 => '><',
120
                "/>\n\s+</"                 => '><',
121
            ];
122
        }
123
124
        return preg_replace(array_keys($replace), array_values($replace), $value);
125
    }
126
}
127