Query   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 56
ccs 15
cts 15
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getQuery() 0 6 1
A setQuery() 0 5 1
A __toString() 0 4 1
A doInitialize() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Purl package, a project by Jonathan H. Wage.
5
 *
6
 * (c) 2013 Jonathan H. Wage
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Purl;
13
14
/**
15
 * Query represents the part of a Url after the question mark (?).
16
 *
17
 * @author      Jonathan H. Wage <[email protected]>
18
 */
19
class Query extends AbstractPart
20
{
21
  /**
22
   * @var string The original query string.
23
   */
24
  private $query;
25
26
  /**
27
   * Construct a new Query instance.
28
   *
29
   * @param string $query
30
   */
31 69
  public function __construct($query = null)
32
  {
33 69
    $this->query = $query;
34 69
  }
35
36
  /**
37
   * Builds a string query from this Query instance internal data and returns it.
38
   *
39
   * @return string
40
   */
41 31
  public function getQuery(): string
42
  {
43 31
    $this->initialize();
44
45 31
    return http_build_query($this->data);
46
  }
47
48
  /**
49
   * Set the string query for this Query instance and sets initialized to false.
50
   *
51
   * @param string
52
   */
53 1
  public function setQuery($query)
54
  {
55 1
    $this->initialized = false;
56 1
    $this->query = $query;
57 1
  }
58
59
  /**
60
   * @inheritDoc
61
   */
62 23
  public function __toString()
63
  {
64 23
    return $this->getQuery();
65
  }
66
67
  /**
68
   * @inheritDoc
69
   */
70 31
  protected function doInitialize()
71
  {
72 31
    parse_str($this->query, $this->data);
73 31
  }
74
}
75