QueryString::toDictionary()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
namespace ValueObjects\Web;
4
5
use ValueObjects\Exception\InvalidNativeArgumentException;
6
use ValueObjects\StringLiteral\StringLiteral;
7
use ValueObjects\Structure\Dictionary;
8
9
class QueryString extends StringLiteral implements QueryStringInterface
10
{
11
    /**
12
     * Returns a new QueryString
13
     *
14
     * @param string $value
15
     */
16 16
    public function __construct($value)
17
    {
18 16
        if (0 === \preg_match('/^\?([\w\.\-[\]~&%+]+(=([\w\.\-~&%+]+)?)?)*$/', $value)) {
19 1
            throw new InvalidNativeArgumentException($value, array('string (valid query string)'));
20
        }
21
22 15
        $this->value = $value;
23 15
    }
24
25
    /**
26
     * Returns a Dictionary structured representation of the query string
27
     *
28
     * @return Dictionary
29
     */
30 2
    public function toDictionary()
31
    {
32 2
        $value = \ltrim($this->toNative(), '?');
33 2
        \parse_str($value, $data);
34
35 2
        return Dictionary::fromNative($data);
36
    }
37
}
38