Passed
Push — master ( 8b508b...69c8c9 )
by Alexander
02:00
created

UrlHelper::append()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 8
cp 0.875
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
crap 2.0078
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 1
            : $parts['scheme'] . '://' . $parts['host'] . $parts['path'] . '?' . $parts['query'];
22
23
    }
24
}
25