Url   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A addOrUpdateArgs() 0 27 6
1
<?php
2
3
namespace ThinKit\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 2
    public static function addOrUpdateArgs(string $url, string $key, mixed $value = null): string
16
    {
17 2
        $a     = parse_url($url);
18 2
        $query = $a['query'] ?? '';
19
20 2
        parse_str($query, $params);
21 2
        $params[$key] = $value;
22 2
        $query        = http_build_query($params);
23
24 2
        $result = '';
25 2
        if (!empty($a['scheme'])) {
26 2
            $result .= $a['scheme'].':';
27
        }
28 2
        if (!empty($a['host'])) {
29 2
            $result .= '//'.$a['host'];
30
        }
31 2
        if (!empty($a['port'])) {
32
            $result .= ':'.$a['port'];
33
        }
34 2
        if (!empty($a['path'])) {
35
            $result .= $a['path'];
36
        }
37 2
        if ($query) {
38 2
            $result .= '?'.$query;
39
        }
40
41 2
        return $result;
42
    }
43
}
44