QueryString::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
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