QueryString   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 29
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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