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

Path::getComponent()   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\Path as PathInterface;
15
16
/**
17
 * Value object representing a URI path component.
18
 *
19
 * @package League.uri
20
 * @author  Ignace Nyamagana Butera <[email protected]>
21
 * @since   1.0.0
22
 */
23
class Path extends AbstractComponent implements PathInterface
24
{
25
    use PathTrait;
26
27
    /**
28
     * @inheritdoc
29
     */
30
    protected static $invalidCharactersRegex = ',[?#],';
31
32
    /**
33
     * new instance
34
     *
35
     * @param string $path the component value
36
     */
37 392
    public function __construct($path = '')
38
    {
39 392
        parent::__construct($this->validateString($path));
40 374
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45 362
    public function getComponent()
46
    {
47 362
        return $this->encodePath($this->data);
48
    }
49
50
    /**
51
     * validate the submitted data
52
     *
53
     * @param string $path
54
     *
55
     * @return string
56
     */
57 380
    protected function validate($path)
58
    {
59 380
        $this->assertValidComponent($path);
60
61 374
        return $this->decodePath($path);
62
    }
63
}
64