Completed
Pull Request — master (#58)
by ignace nyamagana
03:52
created

Fragment   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 1 Features 0
Metric Value
wmc 6
c 7
b 1
f 0
lcom 1
cbo 1
dl 0
loc 62
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A __set_state() 0 7 1
A __debugInfo() 0 4 1
A getUriComponent() 0 9 2
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
     * @inheritdoc
27
     */
28
    protected static $reservedCharactersRegex = "\!\$&'\(\)\*\+,;\=\:\/@\?";
29
30
    /**
31
     * Preserve the delimiter
32
     *
33
     * @var string
34
     */
35
    protected $preserveDelimiter = false;
36
37
    /**
38
     * new instance
39
     *
40
     * @param string|null $data the component value
41
     */
42 625
    public function __construct($data = null)
43
    {
44 625
        if ($data !== null) {
45 382
            $this->preserveDelimiter = true;
0 ignored issues
show
Documentation Bug introduced by
The property $preserveDelimiter was declared of type string, but true is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
46 382
            $this->init($data);
47 246
        }
48 613
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53 12
    public static function __set_state(array $properties)
54
    {
55 12
        $component = new static($properties['data']);
56 12
        $component->preserveDelimiter = $properties['preserveDelimiter'];
57
58 12
        return $component;
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64 2
    public function __debugInfo()
65
    {
66 2
        return ['fragment' => $this->__toString()];
67
    }
68
69
    /**
70
     * Returns the instance string representation
71
     * with its optional URI delimiters
72
     *
73
     * @return string
74
     */
75 629
    public function getUriComponent()
76
    {
77 629
        $component = $this->__toString();
78 629
        if ($this->preserveDelimiter) {
79 368
            return FragmentInterface::DELIMITER.$component;
80
        }
81
82 345
        return $component;
83
    }
84
}
85