Completed
Push — master ( 0168ae...d7f082 )
by ignace nyamagana
02:54
created

Pass   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 54
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 11 3
A getContent() 0 11 2
A getDecoded() 0 8 2
A __debugInfo() 0 4 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.1.0
10
 * @link      https://github.com/thephpleague/uri/
11
 */
12
namespace League\Uri\Components;
13
14
use InvalidArgumentException;
15
use League\Uri\Interfaces\Pass as PassInterface;
16
17
/**
18
 * Value object representing a URI pass component.
19
 *
20
 * @package League.uri
21
 * @author  Ignace Nyamagana Butera <[email protected]>
22
 * @since   1.0.0
23
 */
24
class Pass extends AbstractComponent implements PassInterface
25
{
26
    /**
27
     * @inheritdoc
28
     */
29 933
    protected function validate($str)
30
    {
31 933
        if (!is_string($str) || !preg_match(',[/?#@],', $str)) {
32 930
            return parent::validate($str);
33
        }
34
35 3
        throw new InvalidArgumentException(sprintf(
36 3
            'The encoded pass component `%s` contains invalid characters `/?#@`',
37
            $str
38 2
        ));
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44 456
    public function getContent()
45
    {
46 456
        if (null === $this->data) {
47 255
            return $this->data;
48
        }
49
50 207
        $regexp = '/(?:[^'.self::$unreservedChars.self::$subdelimChars.'\:]+
51 207
            |%(?!'.self::$encodedChars.'))/x';
52
53 207
        return $this->encode((string) $this->data, $regexp);
54
    }
55
56
    /**
57
     * Return the decoded string representation of the component
58
     *
59
     * @return null|string
60
     */
61 30
    public function getDecoded()
62
    {
63 30
        if (null === $this->data) {
64 3
            return null;
65
        }
66
67 27
        return $this->data;
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73 2
    public function __debugInfo()
74
    {
75 2
        return ['pass' => $this->getContent()];
76
    }
77
}
78