Completed
Push — master ( 1fb953...bffbed )
by ignace nyamagana
03:32
created

Fragment::__debugInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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
    /**
27
     * Preserve the delimiter
28
     *
29
     * @var bool
30
     */
31
    protected $preserveDelimiter = false;
32
33
    /**
34
     * new instance
35
     *
36
     * @param string|null $data the component value
37
     */
38 757
    public function __construct($data = null)
39
    {
40 757
        if ($data !== null) {
41 409
            $this->preserveDelimiter = true;
42 409
            $this->data = $this->decodeQueryFragment($this->validateString($data));
43 264
        }
44 745
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49 12
    public static function __set_state(array $properties)
50
    {
51 12
        $component = new static($properties['data']);
52 12
        $component->preserveDelimiter = $properties['preserveDelimiter'];
53
54 12
        return $component;
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60 2
    public function __debugInfo()
61
    {
62 2
        return ['fragment' => $this->__toString()];
63
    }
64
65
    /**
66
     * Returns the component literal value
67
     *
68
     * @return string|null
69
     */
70 763
    public function getContent()
71
    {
72 763
        if (null === $this->data && false === $this->preserveDelimiter) {
73 465
            return null;
74
        }
75
76 397
        return $this->encodeQueryFragment($this->data);
77
    }
78
79
    /**
80
     * Returns the instance string representation
81
     * with its optional URI delimiters
82
     *
83
     * @return string
84
     */
85 761
    public function getUriComponent()
86
    {
87 761
        $component = $this->__toString();
88 761
        if ($this->preserveDelimiter) {
89 395
            return FragmentInterface::DELIMITER.$component;
90
        }
91
92 465
        return $component;
93
    }
94
95
    /**
96
     * Returns an instance with the specified string
97
     *
98
     * This method MUST retain the state of the current instance, and return
99
     * an instance that contains the modified data
100
     *
101
     * @param string $value
102
     *
103
     * @return static
104
     */
105 6
    public function modify($value)
106
    {
107 6
        if (null === $value && $value === $this->getContent()) {
108
            return $this;
109
        }
110
111 6
        if ($value === $this->__toString()) {
112 3
            return $this;
113
        }
114
115 3
        return new static($value);
116
    }
117
}
118