Passed
Push — main ( fcba82...0f5868 )
by PRATIK
14:07 queued 38s
created

logo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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 ?? Auth::user()->profile()->create();
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...
Bug introduced by
The method profile() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

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

70
        $profile = $p ?? Auth::user()->profile ?? Auth::user()->/** @scrutinizer ignore-call */ profile()->create();
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('title')) {
77
    function title()
78
    {
79
        return setting('title', config('adminetic.name', 'Adminetic'));
80
    }
81
}
82
83
if (!function_exists('loader_enabled')) {
84
    function loader_enabled()
85
    {
86
        return setting('loader_enabled', config('adminetic.loader_enabled', true));
87
    }
88
}
89
90
if (!function_exists('favicon')) {
91
    function favicon()
92
    {
93
        return setting('favicon') ? (asset('storage/' . setting('favicon'))) : asset('adminetic/static/favicon.png');
94
    }
95
}
96
97
if (!function_exists('logo')) {
98
    function logo()
99
    {
100
        return setting('logo') ? (asset('storage/' . setting('logo'))) : asset('adminetic/static/logo.png');
101
    }
102
}
103
104
if (!function_exists('dark_logo')) {
105
    function dark_logo()
106
    {
107
        return setting('dark_logo') ? (asset('storage/' . setting('dark_logo'))) : asset('adminetic/static/logo_dark.png');
108
    }
109
}
110
111
if (!function_exists('getLogoBanner')) {
112
    function getLogoBanner()
113
    {
114
        return setting('logo_banner') ? (asset('storage/' . setting('logo_banner'))) : asset('adminetic/static/logo_banner.jpg');
115
    }
116
}
117
118
if (!function_exists('login_register_bg_image')) {
119
    function login_register_bg_image()
120
    {
121
        return setting('login_register_bg_image') ? (asset('storage/' . setting('login_register_bg_image'))) : asset('adminetic/static/login_register_bg_img.jpg');
122
    }
123
}
124
125
if (!function_exists('getLazyLoadImg')) {
126
    function getLazyLoadImg()
127
    {
128
        return asset('adminetic/static/loader.svg');
129
    }
130
}
131
132
if (!function_exists('random_color_part')) {
133
    function random_color_part()
134
    {
135
        return str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT);
136
    }
137
}
138
139
if (!function_exists('random_color')) {
140
    function random_color()
141
    {
142
        return random_color_part() . random_color_part() . random_color_part();
143
    }
144
}
145
146
if (!function_exists('setting')) {
147
    function setting($setting_name, $default = null)
148
    {
149
        $valid_setting_name = strtolower(str_replace(' ', '_', $setting_name));
150
        $setting = \Pratiksh\Adminetic\Models\Admin\Setting::where('setting_name', $valid_setting_name)->first();
151
152
        return isset($setting) ? $setting->value : ($default ?? null);
153
    }
154
}
155
156
if (!function_exists('preference')) {
157
    function preference($preference_name, bool $default = null)
158
    {
159
        $valid_preference_name = strtolower(str_replace(' ', '_', $preference_name));
160
        if (auth()->check()) {
161
            $preference = auth()->user()->preferences()->where('preference', $valid_preference_name)->first();
162
163
            return isset($preference) ? $preference->pivot->enabled : ($default ?? null);
164
        } else {
165
            return null;
166
        }
167
    }
168
}
169
170
if (!function_exists('deleteImage')) {
171
    function deleteImage($image)
172
    {
173
        $image ? (\Illuminate\Support\Facades\File::exists(public_path('storage/' . $image)) ? \Illuminate\Support\Facades\File::delete(public_path('storage/' . $image)) : '') : '';
174
    }
175
}
176
177
if (!function_exists('darkMode')) {
178
    function darkMode()
179
    {
180
        return setting('dark_mode', config('adminetic.dark_mode', false));
181
    }
182
}
183
184
if (!function_exists('getCondition')) {
185
    function getCondition($conditions)
186
    {
187
        $result = null;
188
        if (!isset($conditions)) {
189
            return false;
190
        }
191
192
        if (count($conditions) > 0) {
193
            if (count($conditions) == 1) {
194
                return $conditions[0]['condition'];
195
            } else {
196
                foreach ($conditions as $condition) {
197
                    if (isset($condition['type']) && isset($condition['condition'])) {
198
                        if ($condition['type'] == 'or' || $condition['type'] == 'Or' || $condition['type'] == 'OR' || $condition['type'] == '||') {
199
                            $result = $result || $condition['condition'];
200
                        } elseif ($condition['type'] == 'and' || $condition['type'] == 'And' || $condition['type'] == 'AND' || $condition['type'] == '&&') {
201
                            $result = $result && $condition['condition'];
0 ignored issues
show
introduced by
$result is of type null, thus it always evaluated to false.
Loading history...
202
                        }
203
                    }
204
                }
205
            }
206
207
            return $result;
208
        } else {
209
            return false;
210
        }
211
    }
212
}
213