Code Duplication    Length = 55-58 lines in 3 locations

src/Anshar/Http/UriParts/Fragment.php 1 location

@@ 8-62 (lines=55) @@
5
 * Class Fragment
6
 * @package Subreality\Dilmun\Anshar\Http\UriParts
7
 */
8
class Fragment extends AbstractUriPart
9
{
10
    protected static $unencoded_characters = array("/", "?");
11
12
    protected static $part_pattern;
13
14
    /**
15
     * Fragment constructor. Accepts a string representing a URI fragment. Construction will throw an exception if the
16
     * fragment is not a string.
17
     *
18
     * Construction accepts strings that have been percent-encoded as well as strings that have not been percent-encoded
19
     * and will encode invalid characters.
20
     *
21
     * Construction with a string that includes both encoded and decoded characters will be assumed to be an encoded
22
     * string, resulting in double-encoding.
23
     *
24
     * fragment    = *( pchar / "/" / "?" )
25
     * pchar       = unreserved / pct-encoded / sub-delims / ":" / "@"
26
     * unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
27
     * pct-encoded = "%" HEXDIG HEXDIG
28
     * sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
29
     *
30
     * @see https://tools.ietf.org/html/rfc3986#appendix-A
31
     *
32
     * @throws \InvalidArgumentException
33
     *
34
     * @param string $fragment     A string representing a URI fragment
35
     */
36
    public function __construct($fragment)
37
    {
38
        parent::__construct($fragment, "Fragment");
39
    }
40
41
    /**
42
     * Returns a string representation of the fragment formatted so that it can be compiled into a complete URI string
43
     * per the Uri object's string specification.
44
     *
45
     * If the fragment is empty, toUriString returns an empty string; if the fragment is not empty, toUriString returns
46
     * the fragment prefixed with a octothorpe(#).
47
     *
48
     * @see Uri::__toString
49
     *
50
     * @return string   A string representation of the fragment formatted for a complete URI string
51
     */
52
    public function toUriString()
53
    {
54
        $uri_fragment = parent::toUriString(); //returns data string
55
56
        if (!empty($uri_fragment)) {
57
            $uri_fragment = "#" . $uri_fragment;
58
        }
59
60
        return $uri_fragment;
61
    }
62
}
63

src/Anshar/Http/UriParts/Query.php 1 location

@@ 8-62 (lines=55) @@
5
 * Class Query
6
 * @package Subreality\Dilmun\Anshar\Http\UriParts
7
 */
8
class Query extends AbstractUriPart
9
{
10
    protected static $unencoded_characters = array("/", "?");
11
12
    protected static $part_pattern;
13
14
    /**
15
     * Query constructor. Accepts a string representing a URI query. Construction will throw an exception if the
16
     * query is not a string.
17
     *
18
     * Construction accepts strings that have been percent-encoded as well as strings that have not been percent-encoded
19
     * and will encode invalid characters.
20
     *
21
     * Construction with a string that includes both encoded and decoded characters will be assumed to be an encoded
22
     * string, resulting in double-encoding.
23
     *
24
     * query       = *( pchar / "/" / "?" )
25
     * pchar       = unreserved / pct-encoded / sub-delims / ":" / "@"
26
     * unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
27
     * pct-encoded = "%" HEXDIG HEXDIG
28
     * sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
29
     *
30
     * @see https://tools.ietf.org/html/rfc3986#appendix-A
31
     *
32
     * @throws \InvalidArgumentException
33
     *
34
     * @param string $query     A string representing a URI query
35
     */
36
    public function __construct($query)
37
    {
38
        parent::__construct($query, "Query");
39
    }
40
41
    /**
42
     * Returns a string representation of the query formatted so that it can be compiled into a complete URI string
43
     * per the Uri object's string specification.
44
     *
45
     * If the query is empty, toUriString returns an empty string; if the query is not empty, toUriString returns the
46
     * query prefixed with a question mark.
47
     *
48
     * @see Uri::__toString
49
     *
50
     * @return string   A string representation of the query formatted for a complete URI string
51
     */
52
    public function toUriString()
53
    {
54
        $uri_query = parent::toUriString(); //returns data string
55
56
        if (!empty($uri_query)) {
57
            $uri_query = "?" . $uri_query;
58
        }
59
60
        return $uri_query;
61
    }
62
}
63

src/Anshar/Http/UriParts/UserInfo.php 1 location

@@ 8-65 (lines=58) @@
5
 * Class UserInfo
6
 * @package Subreality\Dilmun\Anshar\Http\UriParts
7
 */
8
class UserInfo extends AbstractUriPart
9
{
10
    protected static $unencoded_characters = array(":");
11
    protected static $compositions         = array(
12
        "unreserved_characters",
13
        "sub_delims_characters",
14
    );
15
16
    protected static $part_pattern;
17
18
    /**
19
     * UserInfo constructor. Accepts a string representing a URI user info component. Construction will throw an
20
     * exception if the user info is not a string.
21
     *
22
     * Construction accepts strings that have been percent-encoded as well as strings that have not been percent-encoded
23
     * and will encode invalid characters.
24
     *
25
     * Construction with a string that includes both encoded and decoded characters will be assumed to be an encoded
26
     * string, resulting in double-encoding.
27
     *
28
     * userinfo    = *( unreserved / pct-encoded / sub-delims / ":" )
29
     * unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
30
     * pct-encoded = "%" HEXDIG HEXDIG
31
     * sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
32
     *
33
     * @see https://tools.ietf.org/html/rfc3986#appendix-A
34
     *
35
     * @throws \InvalidArgumentException
36
     *
37
     * @param string $user_info     A string representing a URI fragment
38
     */
39
    public function __construct($user_info)
40
    {
41
        parent::__construct($user_info, "User info");
42
    }
43
44
    /**
45
     * Returns a string representation of the user info formatted so that it can be compiled into a complete URI string
46
     * per the Uri object's string specification.
47
     *
48
     * If user info is empty, toUriString returns an empty string; if user info is not empty, toUriString returns
49
     * the user info suffixed with an at(@).
50
     *
51
     * @see Uri::__toString
52
     *
53
     * @return string   A string representation of the user info formatted for a complete URI string
54
     */
55
    public function toUriString()
56
    {
57
        $uri_userinfo = parent::toUriString(); //returns data string
58
59
        if (!empty($uri_userinfo)) {
60
            $uri_userinfo = $uri_userinfo . "@";
61
        }
62
63
        return $uri_userinfo;
64
    }
65
}
66