Url   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 37
ccs 18
cts 18
cp 1
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A addOrUpdateArgs() 0 27 6
1
<?php
2
3
namespace ThinkOne\NovaLaravelFilemanager\Helpers;
4
5
class Url
6
{
7
    /**
8
     * Update url arguments.
9
     *
10
     * @param  string  $url
11
     * @param  string  $key
12
     * @param  mixed|null  $value
13
     * @return string
14
     */
15 3
    public static function addOrUpdateArgs(string $url, string $key, mixed $value = null): string
16
    {
17 3
        $a     = parse_url($url);
18 3
        $query = $a['query'] ?? '';
19
20 3
        parse_str($query, $params);
21 3
        $params[$key] = $value;
22 3
        $query        = http_build_query($params);
23
24 3
        $result = '';
25 3
        if (!empty($a['scheme'])) {
26 1
            $result .= $a['scheme'].':';
27
        }
28 3
        if (!empty($a['host'])) {
29 1
            $result .= '//'.$a['host'];
30
        }
31 3
        if (!empty($a['port'])) {
32 1
            $result .= ':'.$a['port'];
33
        }
34 3
        if (!empty($a['path'])) {
35 3
            $result .= $a['path'];
36
        }
37 3
        if ($query) {
38 3
            $result .= '?'.$query;
39
        }
40
41 3
        return $result;
42
    }
43
}
44