Completed
Push — master ( 1bc4b8...c77c49 )
by ignace nyamagana
02:36
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 8
Bugs 0 Features 1
Metric Value
c 8
b 0
f 1
dl 0
loc 54
ccs 10
cts 10
cp 1
rs 10
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.2.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 450
     */
29
    protected function validate($str)
30 450
    {
31 255
        if (!is_string($str) || !preg_match(',[/?#@],', $str)) {
32
            return parent::validate($str);
33
        }
34 201
35 201
        throw new InvalidArgumentException(sprintf(
36
            'The encoded pass component `%s` contains invalid characters `/?#@`',
37 201
            $str
38
        ));
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function getContent()
45 30
    {
46
        if (null === $this->data) {
47 30
            return $this->data;
48
        }
49
50
        $regexp = '/(?:[^'.self::$unreservedChars.self::$subdelimChars.'\:]+
51
            |%(?!'.self::$encodedChars.'))/x';
52
53 2
        return $this->encode((string) $this->data, $regexp);
54
    }
55 2
56
    /**
57
     * Return the decoded string representation of the component
58
     *
59
     * @return null|string
60
     */
61
    public function getDecoded()
62
    {
63
        if (null === $this->data) {
64
            return null;
65
        }
66
67
        return $this->data;
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function __debugInfo()
74
    {
75
        return ['pass' => $this->getContent()];
76
    }
77
}
78