Completed
Push — master ( f56ee5...b16611 )
by ignace nyamagana
06:11
created

Fragment::modify()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.2
cc 4
eloc 6
nc 3
nop 1
crap 4
1
<?php
2
/**
3
 * League.Uri (http://uri.thephpleague.com)
4
 *
5
 * @package   League.uri
6
 * @author    Ignace Nyamagana Butera <[email protected]>
7
 * @copyright 2013-2015 Ignace Nyamagana Butera
8
 * @license   https://github.com/thephpleague/uri/blob/master/LICENSE (MIT License)
9
 * @version   4.2.0
10
 * @link      https://github.com/thephpleague/uri/
11
 */
12
namespace League\Uri\Components;
13
14
use League\Uri\Interfaces\Fragment as FragmentInterface;
15
16
/**
17
 * Value object representing a URI fragment component.
18
 *
19
 * @package League.uri
20
 * @author  Ignace Nyamagana Butera <[email protected]>
21
 * @since   1.0.0
22
 */
23
class Fragment extends AbstractComponent implements FragmentInterface
24
{
25
    /**
26
     * Preserve the delimiter
27
     *
28
     * @var bool
29
     */
30
    protected $preserveDelimiter = false;
31
32
    /**
33
     * new instance
34
     *
35
     * @param string|null $data the component value
36
     */
37 784
    public function __construct($data = null)
38
    {
39 784
        $this->data = $this->validate($data);
40 772
        $this->preserveDelimiter = null !== $data;
41 772
    }
42
43
    /**
44
     * @inheritdoc
45
     */
46 12
    public static function __set_state(array $properties)
47
    {
48 12
        $component = new static($properties['data']);
49 12
        $component->preserveDelimiter = $properties['preserveDelimiter'];
50
51 12
        return $component;
52
    }
53
54
    /**
55
     * Returns the component literal value
56
     *
57
     * @return string|null
58
     */
59 760
    public function getContent()
60
    {
61 760
        if (null === $this->data && false === $this->preserveDelimiter) {
62 456
            return null;
63
        }
64
65 391
        return $this->encodeQueryFragment($this->data);
66
    }
67
68
    /**
69
     * Return the decoded string representation of the component
70
     *
71
     * @return string
72
     */
73 30
    public function getValue()
74
    {
75 30
        return (string) $this->data;
76
    }
77
78
    /**
79
     * Returns the instance string representation
80
     * with its optional URI delimiters
81
     *
82
     * @return string
83
     */
84 725
    public function getUriComponent()
85
    {
86 725
        $component = $this->__toString();
87 725
        if ($this->preserveDelimiter) {
88 383
            return FragmentInterface::DELIMITER.$component;
89
        }
90
91 429
        return $component;
92
    }
93
}
94