Passed
Push — main ( c0bf46...3c443e )
by PRATIK
15:30
created

deleteImage()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 1
c 1
b 0
f 1
nc 4
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
if (!function_exists('getClassesList')) {
4
    function getClassesList($dir)
5
    {
6
        $classes = \File::allFiles($dir);
7
        foreach ($classes as $class) {
8
            $class->classname = str_replace(
0 ignored issues
show
Bug introduced by
The property classname does not seem to exist on Symfony\Component\Finder\SplFileInfo.
Loading history...
9
                [app_path(), '/', '.php'],
10
                ['App', '\\', ''],
11
                $class->getRealPath()
12
            );
13
        }
14
15
        return $classes;
16
    }
17
}
18
if (!function_exists('getAllModelNames')) {
19
    function getAllModelNames($dir)
20
    {
21
        $modelNames = [];
22
        $models = getClassesList($dir);
23
        foreach ($models as $model) {
24
            $model_name = explode('\\', $model->classname);
0 ignored issues
show
Bug introduced by
The property classname does not seem to exist on Symfony\Component\Finder\SplFileInfo.
Loading history...
25
            $modelNames[] = end($model_name);
26
        }
27
28
        return $modelNames;
29
    }
30
}
31
32
if (!function_exists('validImageFolder')) {
33
    function validImageFolder($name, $default = 'default')
34
    {
35
        return strtolower(str_replace([' ', '-', '$', '<', '>', '&', '{', '}', '*', '\\', '/', ':', '.', ';', ',', "'", '"'], '_', $name ?? trim($default)));
36
    }
37
}
38
39
if (!function_exists('getImagePlaceholder')) {
40
    function getImagePlaceholder()
41
    {
42
        return asset('adminetic/static/placeholder.png');
43
    }
44
}
45
46
if (!function_exists('getVerticalImagePlaceholder')) {
47
    function getVerticalImagePlaceholder()
48
    {
49
        return asset('adminetic/static/vertical_placeholder.jpg');
50
    }
51
}
52
53
if (!function_exists('getSliderPlaceholder')) {
54
    function getSliderPlaceholder()
55
    {
56
        return asset('adminetic/static/slider.jpg');
57
    }
58
}
59
60
if (!function_exists('getFoodImagePlaceholder')) {
61
    function getFoodImagePlaceholder()
62
    {
63
        return asset('adminetic/static/food_placeholder.jpg');
64
    }
65
}
66
67
if (!function_exists('getProfilePlaceholder')) {
68
    function getProfilePlaceholder($p = null)
69
    {
70
        $profile = $p ?? Auth::user()->profile;
0 ignored issues
show
Bug introduced by
Accessing profile on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
71
72
        return isset($profile->profile_pic) ? (Illuminate\Support\Str::contains($profile->profile_pic, ['https://', 'http://']) ? $profile->profile_pic : asset('storage/' . $profile->profile_pic)) : asset('adminetic/static/profile.jpg');
73
    }
74
}
75
76
if (!function_exists('getFavicon')) {
77
    function getFavicon()
78
    {
79
        return setting('favicon') ? (asset('storage/' . setting('favicon'))) : asset('adminetic/static/favicon.png');
80
    }
81
}
82
if (!function_exists('getLogo')) {
83
    function getLogo()
84
    {
85
        return setting('logo') ? (asset('storage/' . setting('logo'))) : asset('adminetic/static/logo.png');
86
    }
87
}
88
89
if (!function_exists('getLogoBanner')) {
90
    function getLogoBanner()
91
    {
92
        return setting('logo_banner') ? (asset('storage/' . setting('logo_banner'))) : asset('adminetic/static/logo_banner.jpg');
93
    }
94
}
95
96
if (!function_exists('getLazyLoadImg')) {
97
    function getLazyLoadImg()
98
    {
99
        return asset('website/assets/images/image-bg.svg');
100
    }
101
}
102
103
if (!function_exists('random_color_part')) {
104
    function random_color_part()
105
    {
106
        return str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT);
107
    }
108
}
109
110
if (!function_exists('random_color')) {
111
    function random_color()
112
    {
113
        return random_color_part() . random_color_part() . random_color_part();
114
    }
115
}
116
117
if (!function_exists('setting')) {
118
    function setting($setting_name, $default = null)
119
    {
120
        $valid_setting_name = strtolower(str_replace(' ', '_', $setting_name));
121
        $setting = \Pratiksh\Adminetic\Models\Admin\Setting::where('setting_name', $valid_setting_name)->first();
122
123
        return isset($setting) ? $setting->value : ($default ?? null);
124
    }
125
}
126
127
if (!function_exists('preference')) {
128
    function preference($preference_name, bool $default = null)
129
    {
130
        $valid_preference_name = strtolower(str_replace(' ', '_', $preference_name));
131
        if (auth()->check()) {
132
            $preference = auth()->user()->preferences()->where('preference', $valid_preference_name)->first();
133
134
            return isset($preference) ? $preference->pivot->enabled : ($default ?? null);
135
        } else {
136
            return null;
137
        }
138
    }
139
}
140
141
if (!function_exists('deleteImage')) {
142
    function deleteImage($image)
143
    {
144
        $image ? (\Illuminate\Support\Facades\File::exists(public_path('storage/' . $image)) ? \Illuminate\Support\Facades\File::delete(public_path('storage/' . $image)) : '') : '';
145
    }
146
}
147
148
if (!function_exists('getCondition')) {
149
    function getCondition($conditions)
150
    {
151
        $result = null;
152
        if (!isset($conditions)) {
153
            return false;
154
        }
155
156
        if (count($conditions) > 0) {
157
            if (count($conditions) == 1) {
158
                return $conditions[0]['condition'];
159
            } else {
160
                foreach ($conditions as $condition) {
161
                    if (isset($condition['type']) && isset($condition['condition'])) {
162
                        if ($condition['type'] == 'or' || $condition['type'] == 'Or' || $condition['type'] == 'OR' || $condition['type'] == '||') {
163
                            $result = $result || $condition['condition'];
164
                        } elseif ($condition['type'] == 'and' || $condition['type'] == 'And' || $condition['type'] == 'AND' || $condition['type'] == '&&') {
165
                            $result = $result && $condition['condition'];
0 ignored issues
show
introduced by
$result is of type null, thus it always evaluated to false.
Loading history...
166
                        }
167
                    }
168
                }
169
            }
170
171
            return $result;
172
        } else {
173
            return false;
174
        }
175
    }
176
}
177