Completed
Pull Request — master (#2949)
by
unknown
02:29
created

helpers.php ➔ class_uses_deep()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 2
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
use Illuminate\Support\MessageBag;
4
5
if (!function_exists('admin_path')) {
6
7
    /**
8
     * Get admin path.
9
     *
10
     * @param string $path
11
     *
12
     * @return string
13
     */
14
    function admin_path($path = '')
15
    {
16
        return ucfirst(config('admin.directory')).($path ? DIRECTORY_SEPARATOR.$path : $path);
17
    }
18
}
19
20
if (!function_exists('admin_url')) {
21
    /**
22
     * Get admin url.
23
     *
24
     * @param string $path
25
     * @param mixed  $parameters
26
     * @param bool   $secure
27
     *
28
     * @return string
29
     */
30
    function admin_url($path = '', $parameters = [], $secure = null)
31
    {
32
        if (\Illuminate\Support\Facades\URL::isValidUrl($path)) {
33
            return $path;
34
        }
35
36
        $secure = $secure ?: (config('admin.https') || config('admin.secure'));
37
38
        return url(admin_base_path($path), $parameters, $secure);
39
    }
40
}
41
42
if (!function_exists('admin_base_path')) {
43
    /**
44
     * Get admin url.
45
     *
46
     * @param string $path
47
     *
48
     * @return string
49
     */
50
    function admin_base_path($path = '')
51
    {
52
        $prefix = '/'.trim(config('admin.route.prefix'), '/');
53
54
        $prefix = ($prefix == '/') ? '' : $prefix;
55
56
        $path = trim($path, '/');
57
58
        if (is_null($path) || strlen($path) == 0) {
59
            return $prefix;
60
        }
61
62
        return $prefix.'/'.$path;
63
    }
64
}
65
66 View Code Duplication
if (!function_exists('admin_toastr')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
68
    /**
69
     * Flash a toastr message bag to session.
70
     *
71
     * @param string $message
72
     * @param string $type
73
     * @param array  $options
74
     */
75
    function admin_toastr($message = '', $type = 'success', $options = [])
76
    {
77
        $toastr = new MessageBag(get_defined_vars());
78
79
        session()->flash('toastr', $toastr);
80
    }
81
}
82
83
if (!function_exists('admin_success')) {
84
85
    /**
86
     * Flash a success message bag to session.
87
     *
88
     * @param string $title
89
     * @param string $message
90
     */
91
    function admin_success($title, $message = '')
92
    {
93
        admin_info($title, $message, 'success');
94
    }
95
}
96
97
if (!function_exists('admin_error')) {
98
99
    /**
100
     * Flash a error message bag to session.
101
     *
102
     * @param string $title
103
     * @param string $message
104
     */
105
    function admin_error($title, $message = '')
106
    {
107
        admin_info($title, $message, 'error');
108
    }
109
}
110
111
if (!function_exists('admin_warning')) {
112
113
    /**
114
     * Flash a warning message bag to session.
115
     *
116
     * @param string $title
117
     * @param string $message
118
     */
119
    function admin_warning($title, $message = '')
120
    {
121
        admin_info($title, $message, 'warning');
122
    }
123
}
124
125 View Code Duplication
if (!function_exists('admin_info')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
127
    /**
128
     * Flash a message bag to session.
129
     *
130
     * @param string $title
131
     * @param string $message
132
     * @param string $type
133
     */
134
    function admin_info($title, $message = '', $type = 'info')
135
    {
136
        $message = new MessageBag(get_defined_vars());
137
138
        session()->flash($type, $message);
139
    }
140
}
141
142
if (!function_exists('admin_asset')) {
143
144
    /**
145
     * @param $path
146
     *
147
     * @return string
148
     */
149
    function admin_asset($path)
150
    {
151
        return (config('admin.https') || config('admin.secure')) ? secure_asset($path) : asset($path);
152
    }
153
}
154
155
if (!function_exists('array_delete')) {
156
157
    /**
158
     * Delete from array by value.
159
     *
160
     * @param array $array
161
     * @param mixed $value
162
     */
163
    function array_delete(&$array, $value)
164
    {
165
        foreach ($array as $index => $item) {
166
            if ($value == $item) {
167
                unset($array[$index]);
168
            }
169
        }
170
    }
171
}
172
173
if (!function_exists('class_uses_deep')) {
174
175
    /**
176
     * To get ALL traits including those used by parent classes and other traits
177
     *
178
     * @param $class
179
     * @param bool $autoload
180
     * @return array
181
     */
182
    function class_uses_deep($class, $autoload = true)
183
    {
184
185
        $traits = [];
186
187
        do {
188
            $traits = array_merge(class_uses($class, $autoload), $traits);
189
        } while ($class = get_parent_class($class));
190
191
        foreach ($traits as $trait => $same) {
192
            $traits = array_merge(class_uses($trait, $autoload), $traits);
193
        }
194
195
        return array_unique($traits);
196
    }
197
}
198