Passed
Push — html ( d230bc...4d98c2 )
by Peter
03:13
created

Url::toQuery()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Helper;
6
7
class Url
8
{
9
    /**
10
     * @param array<string,string> $parts
11
     *
12
     * @return string
13
     */
14
    public static function toQuery(array $parts): string
15
    {
16
        if (empty($parts)) {
17
            return '';
18
        }
19
20
        $tmp = [];
21
        foreach ($parts as $k => $v) {
22
            $tmp[] = sprintf('%s=%s', $k, urlencode($v));
23
        }
24
25
        return '?' . implode('&', $tmp);
26
    }
27
}
28