Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — poc-upload-non-breaking ( 5d0aca...6fbcee )
by Pedro
13:41
created

array_merge_recursive_distinct()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 7
c 1
b 0
f 1
nc 3
nop 2
dl 0
loc 12
rs 9.6111
1
<?php
2
3
if (! function_exists('backpack_url')) {
4
    /**
5
     * Appends the configured backpack prefix and returns
6
     * the URL using the standard Laravel helpers.
7
     *
8
     * @param $path
9
     * @return string
10
     */
11
    function backpack_url($path = null, $parameters = [], $secure = null)
12
    {
13
        $path = ! $path || (substr($path, 0, 1) == '/') ? $path : '/'.$path;
14
15
        return url(config('backpack.base.route_prefix', 'admin').$path, $parameters, $secure);
16
    }
17
}
18
19
if (! function_exists('backpack_authentication_column')) {
20
    /**
21
     * Return the username column name.
22
     * The Laravel default (and Backpack default) is 'email'.
23
     *
24
     * @return string
25
     */
26
    function backpack_authentication_column()
27
    {
28
        return config('backpack.base.authentication_column', 'email');
29
    }
30
}
31
32
if (! function_exists('backpack_email_column')) {
33
    /**
34
     * Return the email column name.
35
     * The Laravel default (and Backpack default) is 'email'.
36
     *
37
     * @return string
38
     */
39
    function backpack_email_column()
40
    {
41
        return config('backpack.base.email_column', 'email');
42
    }
43
}
44
45
if (! function_exists('backpack_form_input')) {
46
    /**
47
     * Parse the submitted input in request('form') to an usable array.
48
     * Joins the multiple[] fields in a single key and transform the dot notation fields into arrayed ones.
49
     *
50
     *
51
     * @return array
52
     */
53
    function backpack_form_input()
54
    {
55
        $input = request('form') ?? [];
56
        $result = [];
57
58
        foreach ($input as $row) {
59
            $repeatableRowKey = null;
60
61
            // regular fields don't need any aditional parsing
62
            if (strpos($row['name'], '[') === false) {
63
                $result[$row['name']] = $row['value'];
64
65
                continue;
66
            }
67
68
            // dot notation fields
69
            if (substr_count($row['name'], '[') === 1) {
70
                // start in the first occurence since it's HasOne/MorphOne with dot notation (address[street] in request) to get the input name (address)
71
                $inputNameStart = strpos($row['name'], '[') + 1;
72
            } else {
73
                // repeatable fields, we need to get the input name and the row number
74
                // start on the second occurence since it's a repeatable and we want to bypass the row number (repeatableName[rowNumber][inputName])
75
                $inputNameStart = strpos($row['name'], '[', strpos($row['name'], '[') + 1) + 1;
76
77
                // get the array key (aka repeatable row) from field name
78
                $startKey = strpos($row['name'], '[') + 1;
79
                $endKey = strpos($row['name'], ']', $startKey);
80
                $lengthKey = $endKey - $startKey;
81
                $repeatableRowKey = substr($row['name'], $startKey, $lengthKey);
82
            }
83
84
            $inputNameEnd = strpos($row['name'], ']', $inputNameStart);
85
            $inputNameLength = $inputNameEnd - $inputNameStart;
86
            $inputName = substr($row['name'], $inputNameStart, $inputNameLength);
87
            $parentInputName = substr($row['name'], 0, strpos($row['name'], '['));
88
89
            if (isset($repeatableRowKey)) {
90
                $result[$parentInputName][$repeatableRowKey][$inputName] = $row['value'];
91
92
                continue;
93
            }
94
95
            $result[$parentInputName][$inputName] = $row['value'];
96
        }
97
98
        return $result;
99
    }
100
}
101
102
if (! function_exists('backpack_users_have_email')) {
103
    /**
104
     * Check if the email column is present on the user table.
105
     *
106
     * @return string
107
     */
108
    function backpack_users_have_email()
109
    {
110
        $user_model_fqn = config('backpack.base.user_model_fqn');
111
        $user = new $user_model_fqn();
112
113
        return \Schema::hasColumn($user->getTable(), config('backpack.base.email_column') ?? 'email');
0 ignored issues
show
Bug Best Practice introduced by
The expression return Schema::hasColumn...il_column') ?? 'email') returns the type boolean which is incompatible with the documented return type string.
Loading history...
114
    }
115
}
116
117
if (! function_exists('backpack_avatar_url')) {
118
    /**
119
     * Returns the avatar URL of a user.
120
     *
121
     * @param $user
122
     * @return string
123
     */
124
    function backpack_avatar_url($user)
125
    {
126
        switch (config('backpack.base.avatar_type')) {
127
            case 'gravatar':
128
                if (backpack_users_have_email() && ! empty($user->email)) {
129
                    return Gravatar::fallback(config('backpack.base.gravatar_fallback'))->get($user->email);
0 ignored issues
show
Bug introduced by
The type Gravatar was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
130
                }
131
                break;
132
            default:
133
                return method_exists($user, config('backpack.base.avatar_type')) ? $user->{config('backpack.base.avatar_type')}() : $user->{config('backpack.base.avatar_type')};
134
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
135
        }
136
    }
137
}
138
139
if (! function_exists('backpack_middleware')) {
140
    /**
141
     * Return the key of the middleware used across Backpack.
142
     * That middleware checks if the visitor is an admin.
143
     *
144
     * @param $path
145
     * @return string
146
     */
147
    function backpack_middleware()
148
    {
149
        return config('backpack.base.middleware_key', 'admin');
150
    }
151
}
152
153
if (! function_exists('backpack_guard_name')) {
154
    /*
155
     * Returns the name of the guard defined
156
     * by the application config
157
     */
158
    function backpack_guard_name()
159
    {
160
        return config('backpack.base.guard', config('auth.defaults.guard'));
161
    }
162
}
163
164
if (! function_exists('backpack_auth')) {
165
    /*
166
     * Returns the user instance if it exists
167
     * of the currently authenticated admin
168
     * based off the defined guard.
169
     */
170
    function backpack_auth()
171
    {
172
        return \Auth::guard(backpack_guard_name());
173
    }
174
}
175
176
if (! function_exists('backpack_user')) {
177
    /*
178
     * Returns back a user instance without
179
     * the admin guard, however allows you
180
     * to pass in a custom guard if you like.
181
     */
182
    function backpack_user()
183
    {
184
        return backpack_auth()->user();
185
    }
186
}
187
188
if (! function_exists('mb_ucfirst')) {
189
    /**
190
     * Capitalize the first letter of a string,
191
     * even if that string is multi-byte (non-latin alphabet).
192
     *
193
     * @param  string  $string  String to have its first letter capitalized.
194
     * @param  encoding  $encoding  Character encoding
0 ignored issues
show
Bug introduced by
The type encoding was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
195
     * @return string String with first letter capitalized.
196
     */
197
    function mb_ucfirst($string, $encoding = false)
198
    {
199
        $encoding = $encoding ? $encoding : mb_internal_encoding();
200
201
        $strlen = mb_strlen($string, $encoding);
0 ignored issues
show
Bug introduced by
It seems like $encoding can also be of type true; however, parameter $encoding of mb_strlen() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

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

201
        $strlen = mb_strlen($string, /** @scrutinizer ignore-type */ $encoding);
Loading history...
202
        $firstChar = mb_substr($string, 0, 1, $encoding);
0 ignored issues
show
Bug introduced by
It seems like $encoding can also be of type true; however, parameter $encoding of mb_substr() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

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

202
        $firstChar = mb_substr($string, 0, 1, /** @scrutinizer ignore-type */ $encoding);
Loading history...
203
        $then = mb_substr($string, 1, $strlen - 1, $encoding);
204
205
        return mb_strtoupper($firstChar, $encoding).$then;
0 ignored issues
show
Bug introduced by
It seems like $encoding can also be of type true; however, parameter $encoding of mb_strtoupper() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

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

205
        return mb_strtoupper($firstChar, /** @scrutinizer ignore-type */ $encoding).$then;
Loading history...
206
    }
207
}
208
209
if (! function_exists('backpack_view')) {
210
    /**
211
     * Returns a new displayable view based on the configured backpack view namespace.
212
     * If that view doesn't exist, it will load the one from the original theme.
213
     *
214
     * @param string (see config/backpack/base.php)
0 ignored issues
show
Documentation Bug introduced by
The doc comment (see at position 1 could not be parsed: Expected ')' at position 1, but found 'see'.
Loading history...
215
     * @return string
216
     */
217
    function backpack_view($view)
218
    {
219
        $originalTheme = 'backpack::';
220
        $theme = config('backpack.base.view_namespace');
221
222
        if (is_null($theme)) {
223
            $theme = $originalTheme;
224
        }
225
226
        $returnView = $theme.$view;
227
228
        if (! view()->exists($returnView)) {
229
            $returnView = $originalTheme.$view;
230
        }
231
232
        return $returnView;
233
    }
234
}
235
236
if (! function_exists('square_brackets_to_dots')) {
237
    /**
238
     * Turns a string from bracket-type array to dot-notation array.
239
     * Ex: array[0][property] turns into array.0.property.
240
     *
241
     * @param $path
242
     * @return string
243
     */
244
    function square_brackets_to_dots($string)
245
    {
246
        $string = str_replace(['[', ']'], ['.', ''], $string);
247
248
        return $string;
249
    }
250
}
251
252
if (! function_exists('old_empty_or_null')) {
253
    /**
254
     * This method is an alternative to Laravel's old() helper, which mistakenly
255
     * returns NULL it two cases:
256
     * - if there is an old value, and it was empty or null
257
     * - if there is no old value
258
     * (this is because of the ConvertsEmptyStringsToNull middleware).
259
     *
260
     * In contrast, this method will return:
261
     * - the old value, if there actually is an old value for that key;
262
     * - the second parameter, if there is no old value for that key, but it was empty string or null;
263
     * - null, if there is no old value at all for that key;
264
     *
265
     * @param  string  $key
266
     * @param  array|string  $empty_value
267
     * @return mixed
268
     */
269
    function old_empty_or_null($key, $empty_value = '')
270
    {
271
        $key = square_brackets_to_dots($key);
272
        $old_inputs = session()->getOldInput();
273
274
        // if the input name is present in the old inputs we need to return earlier and not in a coalescing chain
275
        // otherwise `null` aka empty will not pass the condition and the field value would be returned.
276
        if (\Arr::has($old_inputs, $key)) {
277
            return \Arr::get($old_inputs, $key) ?? $empty_value;
278
        }
279
280
        return null;
281
    }
282
}
283
284
if (! function_exists('is_multidimensional_array')) {
285
    /**
286
     * If any of the items inside a given array is an array, the array is considered multidimensional.
287
     *
288
     * @param  array  $array
289
     * @return bool
290
     */
291
    function is_multidimensional_array(array $array)
292
    {
293
        foreach ($array as $item) {
294
            if (is_array($item)) {
295
                return true;
296
            }
297
        }
298
299
        return false;
300
    }
301
}
302
303
if (! function_exists('backpack_pro')) {
304
    /**
305
     * Check if the backpack/pro package is installed.
306
     *
307
     * @return bool
308
     */
309
    function backpack_pro()
310
    {
311
        if (app()->runningUnitTests()) {
0 ignored issues
show
introduced by
The method runningUnitTests() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

311
        if (app()->/** @scrutinizer ignore-call */ runningUnitTests()) {
Loading history...
312
            return true;
313
        }
314
        if (! \Composer\InstalledVersions::isInstalled('backpack/pro')) {
315
            return false;
316
        }
317
318
        return \PackageVersions\Versions::getVersion('backpack/pro');
0 ignored issues
show
Bug Best Practice introduced by
The expression return PackageVersions\V...Version('backpack/pro') returns the type string which is incompatible with the documented return type boolean.
Loading history...
319
    }
320
}
321