Completed
Push — master ( 102700...98b500 )
by Derek
02:15
created

UserInfo::compileUnencodedCharacters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
namespace Subreality\Dilmun\Anshar\Http\UriParts;
3
4
/**
5
 * Class UserInfo
6
 * @package Subreality\Dilmun\Anshar\Http\UriParts
7
 */
8
class UserInfo extends AbstractUriPart
9
{
10
    protected $unencoded_characters = array(":");
11
12
    /**
13
     * UserInfo constructor. Accepts a string representing a URI user info component. Construction will throw an
14
     * exception if the user info is not a string.
15
     *
16
     * Construction accepts strings that have been percent-encoded as well as strings that have not been percent-encoded
17
     * and will encode invalid characters.
18
     *
19
     * Construction with a string that includes both encoded and decoded characters will be assumed to be an encoded
20
     * string, resulting in double-encoding.
21
     *
22
     * userinfo    = *( unreserved / pct-encoded / sub-delims / ":" )
23
     * unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
24
     * pct-encoded = "%" HEXDIG HEXDIG
25
     * sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
26
     *
27
     * @see https://tools.ietf.org/html/rfc3986#appendix-A
28
     *
29
     * @throws \InvalidArgumentException
30
     *
31
     * @param string $user_info     A string representing a URI fragment
32
     */
33 12
    public function __construct($user_info)
34
    {
35 12
        parent::__construct($user_info, "User info");
36 6
    }
37
38
    /**
39
     * Compiles a regexp pattern based on predefined patterns that define allowed characters for user info
40
     */
41 12 View Code Duplication
    protected function compileValidPattern()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43 12
        self::$valid_pattern = '/^([\/\?' .
44 12
            $this->unreserved_pattern .
45 12
            $this->sub_delims_pattern .
46 12
            ']|' .                          //predefined patterns or percent-encoding
47 12
            $this->pct_encoded_pattern .
48 12
            ')*$/';
49 12
    }
50
51
    /**
52
     * Compiles an array of legal characters for user info based upon the RFC3986 specification:
53
     *
54
     * userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
55
     */
56 12
    protected function compileUnencodedCharacters()
57
    {
58 12
        $this->unencoded_characters = array_merge(
59 12
            $this->unencoded_characters,
60 12
            $this->unreserved_characters,
61 12
            $this->sub_delims_characters
62 12
        );
63 12
    }
64
}
65