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

UserInfo   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 15.79 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 2
cbo 1
dl 9
loc 57
ccs 18
cts 18
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A compileValidPattern() 9 9 1
A compileUnencodedCharacters() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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