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
|
|
|
|
32
|
|
|
if (true === config('helper.abbrv.to_uppercase')) { |
33
|
|
|
$value = strtoupper($value); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if (true == config('helper.abbrv.unique_characters') || true == $unique_characters) { |
37
|
|
|
$split = str_split($value); |
38
|
|
|
$unique_characters = []; |
39
|
|
|
foreach ($split as $character) { |
40
|
|
|
if (! in_array($character, $unique_characters)) { |
41
|
|
|
$unique_characters[] = $character; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return implode('', $unique_characters); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $value; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/* |
53
|
|
|
* Get Fully Qualified Class Name (FQCN) for an Object |
54
|
|
|
*/ |
55
|
|
|
if (! function_exists('fqcn')) { |
56
|
|
|
function fqcn($object) |
57
|
|
|
{ |
58
|
|
|
return get_class($object); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/* |
63
|
|
|
* Get Slug Name for Fully Qualified Class Name (FQCN) |
64
|
|
|
*/ |
65
|
|
|
if (! function_exists('str_slug_fqcn')) { |
66
|
|
|
function str_slug_fqcn($object) |
67
|
|
|
{ |
68
|
|
|
return Str::kebab(fqcn($object)); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/* |
73
|
|
|
* Send Notification To User |
74
|
|
|
*/ |
75
|
|
|
if (! function_exists('notify')) { |
76
|
|
|
function notify($identifier, $column = 'id') |
77
|
|
|
{ |
78
|
|
|
return \CleaniqueCoders\LaravelHelper\Services\NotificationService::make($identifier, $column); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/* |
83
|
|
|
* user() helper |
84
|
|
|
*/ |
85
|
|
|
if (! function_exists('user')) { |
86
|
|
|
function user() |
87
|
|
|
{ |
88
|
|
|
foreach (config('auth.guards') as $key => $value) { |
89
|
|
|
if (Auth::guard($key)->check()) { |
90
|
|
|
return Auth::guard($key)->user(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return null; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/* |
99
|
|
|
* Minify given HTML Content |
100
|
|
|
*/ |
101
|
|
|
if (! function_exists('minify')) { |
102
|
|
|
function minify($value) |
103
|
|
|
{ |
104
|
|
|
$replace = [ |
105
|
|
|
'/<!--[^\[](.*?)[^\]]-->/s' => '', |
106
|
|
|
"/<\?php/" => '<?php ', |
107
|
|
|
"/\n([\S])/" => '$1', |
108
|
|
|
"/\r/" => '', |
109
|
|
|
"/\n/" => '', |
110
|
|
|
"/\t/" => '', |
111
|
|
|
'/ +/' => ' ', |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
if (false !== strpos($value, '<pre>')) { |
115
|
|
|
$replace = [ |
116
|
|
|
'/<!--[^\[](.*?)[^\]]-->/s' => '', |
117
|
|
|
"/<\?php/" => '<?php ', |
118
|
|
|
"/\r/" => '', |
119
|
|
|
"/>\n</" => '><', |
120
|
|
|
"/>\s+\n</" => '><', |
121
|
|
|
"/>\n\s+</" => '><', |
122
|
|
|
]; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return preg_replace(array_keys($replace), array_values($replace), $value); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|
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.