Completed
Push — master ( 1bc4b8...c77c49 )
by ignace nyamagana
02:36
created

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