Completed
Push — master ( 4b40ba...4de594 )
by ignace nyamagana
03:31
created

AbstractComponent::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
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\Types\ImmutableComponentTrait;
15
16
/**
17
 * An abstract class to ease component manipulation
18
 *
19
 * @package League.uri
20
 * @author  Ignace Nyamagana Butera <[email protected]>
21
 * @since   4.0.0
22
 */
23
abstract class AbstractComponent
24
{
25
    use ImmutableComponentTrait;
26
27
    /**
28
     * The component data
29
     *
30
     * @var int|string
31
     */
32
    protected $data;
33
34
    /**
35
     * @inheritdoc
36
     */
37 12
    public static function __set_state(array $properties)
38
    {
39 12
        return new static($properties['data']);
40
    }
41
42
    /**
43
     * new instance
44
     *
45
     * @param string|null $data the component value
46
     */
47 1055
    public function __construct($data = null)
48
    {
49 1055
        if ($data !== null) {
50 1019
            $this->init($data);
51 646
        }
52 1007
    }
53
54
    /**
55
     * Set data.
56
     *
57
     * @param mixed $data The data to set.
58
     */
59 972
    protected function init($data)
60
    {
61 972
        $data = $this->validateString($data);
62 960
        $this->data = $this->validate($data);
0 ignored issues
show
Bug introduced by
The method validate() does not exist on League\Uri\Components\AbstractComponent. Did you maybe mean validateString()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
63 951
    }
64
65
    /**
66
     * The component raw data
67
     *
68
     * @return string|null
69
     */
70 859
    public function getContent()
71
    {
72 859
        return $this->data;
73
    }
74
75
    /**
76
     * Returns the instance string representation; If the
77
     * instance is not defined an empty string is returned
78
     *
79
     * @return string
80
     */
81 832
    public function __toString()
82
    {
83 832
        return (string) $this->getContent();
84
    }
85
86
    /**
87
     * Returns the instance string representation
88
     * with its optional URI delimiters
89
     *
90
     * @return string
91
     */
92 180
    public function getUriComponent()
93
    {
94 180
        return $this->__toString();
95
    }
96
97
    /**
98
     * Returns an instance with the specified string
99
     *
100
     * This method MUST retain the state of the current instance, and return
101
     * an instance that contains the modified data
102
     *
103
     * @param string $value
104
     *
105
     * @return static
106
     */
107 387
    public function modify($value)
108
    {
109 387
        if ($value === $this->getContent()) {
110 258
            return $this;
111
        }
112
113 339
        return new static($value);
114
    }
115
}
116