Completed
Pull Request — master (#21)
by Alexander
28:17 queued 05:36
created

UrlHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 20
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A append() 0 17 2
1
<?php
2
3
namespace Horat1us\Yii\Helpers;
4
5
/**
6
 * Class UrlHelper
7
 * @package Horat1us\Yii\Helpers
8
 */
9
class UrlHelper
10
{
11 1
    public static function append(string $url, array $params = []): string
12
    {
13 1
        $parts = parse_url($url);
14 1
        parse_str($parts['query'] ?? '', $existParams);
15
16 1
        $mergedParams = array_merge($existParams, $params);
17 1
        $parts['query'] = http_build_query($mergedParams);
18
19 1
        return function_exists('http_build_url')
20
            ? http_build_url($parts)
21
            : (
22 1
                ($parts['scheme'] ?? 'http')
23 1
                . '://' . ($parts['host'] ?? 'localhost')
24 1
                . ($parts['path'] ?? '')
25 1
                . '?' . $parts['query']
26
            );
27
    }
28
}
29