Completed
Push — master ( 763db7...ef6780 )
by ignace nyamagana
04:05
created

Fragment::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
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
     * Returns the component literal value
27
     *
28
     * @return string|null
29
     */
30 760
    public function getContent()
31
    {
32 760
        if (null === $this->data) {
33 456
            return null;
34
        }
35
36 391
        $regexp = '/(?:[^'.self::$unreservedChars.self::$subdelimChars.'\:\/@\?]+
37 391
            |%(?!'.self::$encodedChars.'))/x';
38
39 391
        return $this->encode($this->data, $regexp);
40
    }
41
42
    /**
43
     * Return the decoded string representation of the component
44
     *
45
     * @return string
46
     */
47 30
    public function getValue()
48
    {
49 30
        return (string) $this->data;
50
    }
51
52
    /**
53
     * Returns the instance string representation
54
     * with its optional URI delimiters
55
     *
56
     * @return string
57
     */
58 725
    public function getUriComponent()
59
    {
60 725
        $component = $this->__toString();
61 725
        if (null !== $this->data) {
62 383
            return FragmentInterface::DELIMITER.$component;
63
        }
64
65 429
        return $component;
66
    }
67
}
68