Completed
Push — master ( 98b500...211af5 )
by Derek
03:45
created

Fragment::compileUnencodedCharacters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 9.6666
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
namespace Subreality\Dilmun\Anshar\Http\UriParts;
3
4
/**
5
 * Class Fragment
6
 * @package Subreality\Dilmun\Anshar\Http\UriParts
7
 */
8 View Code Duplication
class Fragment extends AbstractUriPart
9
{
10
    protected $unencoded_characters = array("/", "?");
11
12
    /**
13
     * Fragment constructor. Accepts a string representing a URI fragment. Construction will throw an exception if the
14
     * fragment 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
     * fragment    = *( pchar / "/" / "?" )
23
     * pchar       = unreserved / pct-encoded / sub-delims / ":" / "@"
24
     * unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
25
     * pct-encoded = "%" HEXDIG HEXDIG
26
     * sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
27
     *
28
     * @see https://tools.ietf.org/html/rfc3986#appendix-A
29
     *
30
     * @throws \InvalidArgumentException
31
     *
32
     * @param string $fragment     A string representing a URI fragment
33
     */
34 87
    public function __construct($fragment)
35
    {
36 87
        parent::__construct($fragment, "Fragment");
37 81
    }
38
39
    /**
40
     * Returns a string representation of the fragment formatted so that it can be compiled into a complete URI string
41
     * per the Uri object's string specification.
42
     *
43
     * If the fragment is empty, toUriString returns an empty string; if the fragment is not empty, toUriString returns
44
     * the fragment prefixed with a octothorpe(#).
45
     *
46
     * @see Uri::__toString
47
     *
48
     * @return string   A string representation of the fragment formatted for a complete URI string
49
     */
50 33
    public function toUriString()
51
    {
52 33
        $uri_fragment = parent::toUriString(); //returns data string
53
54 33
        if (!empty($uri_fragment)) {
55 28
            $uri_fragment = "#" . $uri_fragment;
56 28
        }
57
58 33
        return $uri_fragment;
59
    }
60
}
61