Completed
Pull Request — master (#39)
by ignace nyamagana
03:45
created

Path::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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.1.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 $reservedCharactersRegex = "\!\$&'\(\)\*\+,;\=\:\/@\?%";
31
32
    /**
33
     * @inheritdoc
34
     */
35
    protected static $invalidCharactersRegex = ',[?#],';
36
37
    /**
38
     * new instance
39
     *
40
     * @param string $path the component value
41
     */
42 390
    public function __construct($path = '')
43
    {
44 390
        parent::__construct($this->validateString($path));
45 372
    }
46
47
    /**
48
     * validate the submitted data
49
     *
50
     * @param string $path
51
     *
52
     * @return string
53
     */
54 378
    protected function validate($path)
55
    {
56 378
        $this->assertValidComponent($path);
57
58 372
        return preg_replace_callback(
59 372
            '/(?:[^'.static::$reservedCharactersRegex.']+|%(?![A-Fa-f0-9]{2}))/S',
60 372
            [$this, 'decodeSegmentPart'],
61
            $path
62 248
        );
63
    }
64
}
65