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

Utils   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 6
c 0
b 0
f 0
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A buildUrl() 0 8 2
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
}