Passed
Push — master ( 473b33...57ebbd )
by Shahrad
01:22
created

Utils::buildUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 3
1
<?php
2
3
namespace EasyHttp\Util;
4
5
/**
6
 * Utils
7
 *
8
 * @link    https://github.com/shahradelahi/easy-http
9
 * @author  Shahrad Elahi (https://github.com/shahradelahi)
10
 * @license https://github.com/shahradelahi/easy-http/blob/master/LICENSE (MIT License)
11
 */
12
class Utils
13
{
14
15
    /**
16
     * Builds url from array of parameters
17
     *
18
     * @param string $base The base url
19
     * @param array $body Each segment of the url
20
     * @param array $params The query string parameters
21
     * @return string
22
     */
23
    public static function buildUrl(string $base, array $body, array $params): string
24
    {
25
        $url = $base;
26
        $url .= '/' . implode('/', $body);
27
        if (count($params) > 0) {
28
            $url .= '?' . http_build_query($params);
29
        }
30
        return $url;
31
    }
32
33
}