Completed
Push — master ( fb040e...52ef18 )
by Abdelrahman
10:47 queued 09:24
created

helpers.php ➔ extract_title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
use Illuminate\Support\Str;
6
use Illuminate\Support\HtmlString;
7
8
if (! function_exists('extract_title')) {
9
    /**
10
     * Extract page title from breadcrumbs.
11
     *
12
     * @return string
13
     */
14
    function extract_title(HtmlString $breadcrumbs, string $separator = ' » ')
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
15
    {
16
        return strip_tags(str_replace_last($separator, '', str_replace('</li>', $separator, $breadcrumbs)));
17
    }
18
}
19
20
if (! function_exists('domain')) {
21
    /**
22
     * Return domain host.
23
     *
24
     * @return string
25
     */
26
    function domain()
27
    {
28
        return parse_url(config('app.url'))['host'];
29
    }
30
}
31
32
if (! function_exists('intend')) {
33
    /**
34
     * Return redirect response.
35
     *
36
     * @param array $arguments
37
     * @param int   $status
38
     *
39
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
40
     */
41
    function intend(array $arguments, int $status = 302)
42
    {
43
        $redirect = redirect(array_pull($arguments, 'url'), $status);
44
45
        if (request()->expectsJson()) {
46
            $response = collect($arguments['withErrors'] ?? $arguments['with']);
47
48
            return response()->json([$response->flatten()->first() ?? 'OK']);
49
        }
50
51
        foreach ($arguments as $key => $value) {
52
            $redirect = in_array($key, ['home', 'back']) ? $redirect->{$key}() : $redirect->{$key}($value);
53
        }
54
55
        return $redirect;
56
    }
57
}
58
59
if (! function_exists('lower_case')) {
60
    /**
61
     * Convert the given string to lower-case.
62
     *
63
     * @param string $value
64
     *
65
     * @return string
66
     */
67
    function lower_case($value)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
68
    {
69
        return Str::lower($value);
70
    }
71
}
72
73
if (! function_exists('upper_case')) {
74
    /**
75
     * Convert the given string to upper-case.
76
     *
77
     * @param string $value
78
     *
79
     * @return string
80
     */
81
    function upper_case($value)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
82
    {
83
        return Str::upper($value);
84
    }
85
}
86
87
if (! function_exists('mimetypes')) {
88
    /**
89
     * Get valid mime types.
90
     *
91
     * @see https://github.com/symfony/http-foundation/blob/3.0/File/MimeType/MimeTypeExtensionGuesser.php
92
     * @see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
93
     *
94
     * @return array
95
     */
96
    function mimetypes()
97
    {
98
        return json_decode(file_get_contents(__DIR__.'/../../resources/data/mimetypes.json'), true);
99
    }
100
}
101
102
if (! function_exists('timezones')) {
103
    /**
104
     * Get valid timezones.
105
     * This list is based upon the timezone database version 2017.2.
106
     *
107
     * @see http://php.net/manual/en/timezones.php
108
     *
109
     * @return array
110
     */
111
    function timezones()
112
    {
113
        return json_decode(file_get_contents(__DIR__.'/../../resources/data/timezones.json'), true);
114
    }
115
}
116
117
if (! function_exists('array_search_recursive')) {
118
    /**
119
     * Recursively searches the array for a given value and returns the corresponding key if successful.
120
     *
121
     * @param mixed $needle
122
     * @param array $haystack
123
     *
124
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use integer|string|false.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
125
     */
126
    function array_search_recursive($needle, $haystack)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
127
    {
128
        foreach ($haystack as $key => $value) {
129
            $current_key = $key;
130
            if ($needle === $value || (is_array($value) && array_search_recursive($needle, $value) !== false)) {
131
                return $current_key;
132
            }
133
        }
134
135
        return false;
136
    }
137
}
138
139
if (! function_exists('array_trim_recursive')) {
140
    /**
141
     * Recursively trim elements of the given array.
142
     *
143
     * @param mixed  $values
144
     * @param string $charlist
145
     *
146
     * @return mixed
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array|object|integer|double|null|boolean|string.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
147
     */
148
    function array_trim_recursive($values, $charlist = " \t\n\r\0\x0B")
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
149
    {
150
        if (is_array($values)) {
151
            return array_map('array_trim_recursive', $values);
152
        }
153
154
        return is_string($values) ? trim($values, $charlist) : $values;
155
    }
156
}
157
158
if (! function_exists('array_filter_recursive')) {
159
    /**
160
     * Recursively filter empty strings and null elements of the given array.
161
     *
162
     * @param array $values
163
     * @param bool  $strOnly
164
     *
165
     * @return mixed
166
     */
167
    function array_filter_recursive($values, $strOnly = true)
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
168
    {
169
        foreach ($values as &$value) {
170
            if (is_array($value)) {
171
                $value = array_filter_recursive($value);
172
            }
173
        }
174
175
        return ! $strOnly ? array_filter($values) : array_filter($values, function ($item) {
176
            return ! is_null($item) && ! ((is_string($item) || is_array($item)) && empty($item));
177
        });
178
    }
179
}
180