Completed
Push — master ( 03e1a0...07d10c )
by ignace nyamagana
04:33
created

Fragment::getDecoded()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 8
ccs 2
cts 2
cp 1
crap 2
rs 9.4285
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
     * Returns the component literal value
27
     *
28
     * @return string|null
29
     */
30 829
    public function getContent()
31
    {
32 829
        if (null === $this->data) {
33 525
            return null;
34
        }
35
36 403
        $regexp = '/(?:[^'.self::$unreservedChars.self::$subdelimChars.'\:\/@\?]+
37 403
            |%(?!'.self::$encodedChars.'))/x';
38
39 403
        return $this->encode($this->data, $regexp);
40
    }
41
42
    /**
43
     * Return the decoded string representation of the component
44
     *
45
     * @return null|string
46
     */
47 30
    public function getDecoded()
48
    {
49 30
        if (null === $this->data) {
50
            return null;
51
        }
52
53
        return $this->data;
54
    }
55
56
    /**
57
     * Returns the instance string representation
58 806
     * with its optional URI delimiters
59
     *
60 806
     * @return string
61 806
     */
62 392
    public function getUriComponent()
63
    {
64
        $component = $this->__toString();
65 510
        if (null !== $this->data) {
66
            return FragmentInterface::DELIMITER.$component;
67
        }
68
69
        return $component;
70
    }
71 2
72
    /**
73 2
     * @inheritdoc
74
     */
75
    public function __debugInfo()
76
    {
77
        return ['fragment' => $this->getContent()];
78
    }
79
}
80