QueryStringParser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 20
ccs 7
cts 8
cp 0.875
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 14 4
1
<?php
2
3
namespace BenTools\MercurePHP\Helpers;
4
5
use BenTools\QueryString\Parser\QueryStringParserInterface;
6
7
use function BenTools\QueryString\pairs;
8
9
final class QueryStringParser implements QueryStringParserInterface
10
{
11
    private const FORCE_PARAM_AS_ARRAY = [
12
        'topic',
13
    ];
14
15 3
    public function parse(string $queryString): array
16
    {
17 3
        $params = [];
18
19 3
        foreach (pairs($queryString) as $key => $value) {
20 2
            if (isset($params[$key]) || \in_array($key, self::FORCE_PARAM_AS_ARRAY, true)) {
21 2
                $params[$key] = (array) ($params[$key] ?? null);
22 2
                $params[$key][] = $value;
23
            } else {
24
                $params[$key] = $value;
25
            }
26
        }
27
28 3
        return $params;
29
    }
30
}
31