Completed
Push — master ( 646e95...28cd62 )
by Derek
02:00
created

Uri::getQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace Subreality\Dilmun\Anshar\Http;
3
4
use Psr\Http\Message\UriInterface;
5
6
class Uri implements UriInterface
7
{
8
    /** @var  string */
9
    protected $uri_string;
10
11
    /** @var string */
12
    protected $scheme = "";
13
14
    /** @var  string */
15
    protected $hier_part;
16
17
    /** @var string */
18
    protected $authority;
19
20
    /** @var string */
21
    protected $user_info;
22
23
    /** @var string */
24
    protected $host;
25
26
    /** @var integer */
27
    protected $port;
28
29
    /** @var string */
30
    protected $path;
31
32
    /** @var string */
33
    protected $query;
34
35
    /** @var string */
36
    protected $fragment;
37
38
    /**
39
     * Uri constructor.
40
     *
41
     * @param string $uri
42
     */
43 31
    public function __construct($uri)
44
    {
45 31
        if (!is_string($uri)) {
46 6
            throw new \InvalidArgumentException("New Uri objects must be constructed with a string URI");
47
        }
48
49 25
        $uri_parts = $this->explodeUri($uri);
50
51 25
        $this->scheme       = $uri_parts["scheme"];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 7 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
52 25
        $this->authority    = $uri_parts["authority"];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 4 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
53 25
        $this->user_info    = $uri_parts["user_info"];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 4 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
54 25
        $this->host         = $uri_parts["host"];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 9 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
55 25
        $this->port         = $uri_parts["port"];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 9 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
56 25
        $this->path         = $uri_parts["path"];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 9 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
57 25
        $this->query        = $uri_parts["query"];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 8 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
58 25
        $this->fragment     = $uri_parts["fragment"];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 5 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
59 25
    }
60
61
    /**
62
     * Retrieve the scheme component of the URI.
63
     *
64
     * If no scheme is present, this method MUST return an empty string.
65
     *
66
     * The value returned MUST be normalized to lowercase, per RFC 3986
67
     * Section 3.1.
68
     *
69
     * The trailing ":" character is not part of the scheme and MUST NOT be
70
     * added.
71
     *
72
     * @see https://tools.ietf.org/html/rfc3986#section-3.1
73
     * @return string The URI scheme.
74
     */
75 3
    public function getScheme()
76
    {
77 3
        return $this->scheme;
78
    }
79
80
    /**
81
     * Retrieve the authority component of the URI.
82
     *
83
     * If no authority information is present, this method MUST return an empty
84
     * string.
85
     *
86
     * The authority syntax of the URI is:
87
     *
88
     * <pre>
89
     * [user-info@]host[:port]
90
     * </pre>
91
     *
92
     * If the port component is not set or is the standard port for the current
93
     * scheme, it SHOULD NOT be included.
94
     *
95
     * @see https://tools.ietf.org/html/rfc3986#section-3.2
96
     * @return string The URI authority, in "[user-info@]host[:port]" format.
97
     */
98 3
    public function getAuthority()
99
    {
100 3
        return $this->authority;
101
    }
102
103
    /**
104
     * Retrieve the user information component of the URI.
105
     *
106
     * If no user information is present, this method MUST return an empty
107
     * string.
108
     *
109
     * If a user is present in the URI, this will return that value;
110
     * additionally, if the password is also present, it will be appended to the
111
     * user value, with a colon (":") separating the values.
112
     *
113
     * The trailing "@" character is not part of the user information and MUST
114
     * NOT be added.
115
     *
116
     * @return string The URI user information, in "username[:password]" format.
117
     */
118 3
    public function getUserInfo()
119
    {
120 3
        return $this->user_info;
121
    }
122
123
    /**
124
     * Retrieve the host component of the URI.
125
     *
126
     * If no host is present, this method MUST return an empty string.
127
     *
128
     * The value returned MUST be normalized to lowercase, per RFC 3986
129
     * Section 3.2.2.
130
     *
131
     * @see http://tools.ietf.org/html/rfc3986#section-3.2.2
132
     * @return string The URI host.
133
     */
134 3
    public function getHost()
135
    {
136 3
        return $this->host;
137
    }
138
139
    /**
140
     * Retrieve the port component of the URI.
141
     *
142
     * If a port is present, and it is non-standard for the current scheme,
143
     * this method MUST return it as an integer. If the port is the standard port
144
     * used with the current scheme, this method SHOULD return null.
145
     *
146
     * If no port is present, and no scheme is present, this method MUST return
147
     * a null value.
148
     *
149
     * If no port is present, but a scheme is present, this method MAY return
150
     * the standard port for that scheme, but SHOULD return null.
151
     *
152
     * @return null|int The URI port.
153
     */
154 3
    public function getPort()
155
    {
156 3
        return $this->port;
157
    }
158
159
    /**
160
     * Retrieve the path component of the URI.
161
     *
162
     * The path can either be empty or absolute (starting with a slash) or
163
     * rootless (not starting with a slash). Implementations MUST support all
164
     * three syntaxes.
165
     *
166
     * Normally, the empty path "" and absolute path "/" are considered equal as
167
     * defined in RFC 7230 Section 2.7.3. But this method MUST NOT automatically
168
     * do this normalization because in contexts with a trimmed base path, e.g.
169
     * the front controller, this difference becomes significant. It's the task
170
     * of the user to handle both "" and "/".
171
     *
172
     * The value returned MUST be percent-encoded, but MUST NOT double-encode
173
     * any characters. To determine what characters to encode, please refer to
174
     * RFC 3986, Sections 2 and 3.3.
175
     *
176
     * As an example, if the value should include a slash ("/") not intended as
177
     * delimiter between path segments, that value MUST be passed in encoded
178
     * form (e.g., "%2F") to the instance.
179
     *
180
     * @see https://tools.ietf.org/html/rfc3986#section-2
181
     * @see https://tools.ietf.org/html/rfc3986#section-3.3
182
     * @return string The URI path.
183
     */
184 3
    public function getPath()
185
    {
186 3
        return $this->path;
187
    }
188
189
    /**
190
     * Retrieve the query string of the URI.
191
     *
192
     * If no query string is present, this method MUST return an empty string.
193
     *
194
     * The leading "?" character is not part of the query and MUST NOT be
195
     * added.
196
     *
197
     * The value returned MUST be percent-encoded, but MUST NOT double-encode
198
     * any characters. To determine what characters to encode, please refer to
199
     * RFC 3986, Sections 2 and 3.4.
200
     *
201
     * As an example, if a value in a key/value pair of the query string should
202
     * include an ampersand ("&") not intended as a delimiter between values,
203
     * that value MUST be passed in encoded form (e.g., "%26") to the instance.
204
     *
205
     * @see https://tools.ietf.org/html/rfc3986#section-2
206
     * @see https://tools.ietf.org/html/rfc3986#section-3.4
207
     * @return string The URI query string.
208
     */
209 3
    public function getQuery()
210
    {
211 3
        return $this->query;
212
    }
213
214
    /**
215
     * Retrieve the fragment component of the URI.
216
     *
217
     * If no fragment is present, this method MUST return an empty string.
218
     *
219
     * The leading "#" character is not part of the fragment and MUST NOT be
220
     * added.
221
     *
222
     * The value returned MUST be percent-encoded, but MUST NOT double-encode
223
     * any characters. To determine what characters to encode, please refer to
224
     * RFC 3986, Sections 2 and 3.5.
225
     *
226
     * @see https://tools.ietf.org/html/rfc3986#section-2
227
     * @see https://tools.ietf.org/html/rfc3986#section-3.5
228
     * @return string The URI fragment.
229
     */
230 3
    public function getFragment()
231
    {
232 3
        return $this->fragment;
233
    }
234
235
    /**
236
     * Return an instance with the specified scheme.
237
     *
238
     * This method MUST retain the state of the current instance, and return
239
     * an instance that contains the specified scheme.
240
     *
241
     * Implementations MUST support the schemes "http" and "https" case
242
     * insensitively, and MAY accommodate other schemes if required.
243
     *
244
     * An empty scheme is equivalent to removing the scheme.
245
     *
246
     * @param string $scheme The scheme to use with the new instance.
247
     * @return static A new instance with the specified scheme.
0 ignored issues
show
Documentation introduced by
Should the return type not be Uri|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
248
     * @throws \InvalidArgumentException for invalid or unsupported schemes.
249
     */
250
    public function withScheme($scheme)
251
    {
252
        // TODO: Implement withScheme() method.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
253
    }
254
255
    /**
256
     * Return an instance with the specified user information.
257
     *
258
     * This method MUST retain the state of the current instance, and return
259
     * an instance that contains the specified user information.
260
     *
261
     * Password is optional, but the user information MUST include the
262
     * user; an empty string for the user is equivalent to removing user
263
     * information.
264
     *
265
     * @param string $user The user name to use for authority.
266
     * @param null|string $password The password associated with $user.
267
     * @return static A new instance with the specified user information.
0 ignored issues
show
Documentation introduced by
Should the return type not be Uri|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
268
     */
269
    public function withUserInfo($user, $password = null)
270
    {
271
        // TODO: Implement withUserInfo() method.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
272
    }
273
274
    /**
275
     * Return an instance with the specified host.
276
     *
277
     * This method MUST retain the state of the current instance, and return
278
     * an instance that contains the specified host.
279
     *
280
     * An empty host value is equivalent to removing the host.
281
     *
282
     * @param string $host The hostname to use with the new instance.
283
     * @return static A new instance with the specified host.
0 ignored issues
show
Documentation introduced by
Should the return type not be Uri|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
284
     * @throws \InvalidArgumentException for invalid hostnames.
285
     */
286
    public function withHost($host)
287
    {
288
        // TODO: Implement withHost() method.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
289
    }
290
291
    /**
292
     * Return an instance with the specified port.
293
     *
294
     * This method MUST retain the state of the current instance, and return
295
     * an instance that contains the specified port.
296
     *
297
     * Implementations MUST raise an exception for ports outside the
298
     * established TCP and UDP port ranges.
299
     *
300
     * A null value provided for the port is equivalent to removing the port
301
     * information.
302
     *
303
     * @param null|int $port The port to use with the new instance; a null value
304
     *     removes the port information.
305
     * @return static A new instance with the specified port.
0 ignored issues
show
Documentation introduced by
Should the return type not be Uri|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
306
     * @throws \InvalidArgumentException for invalid ports.
307
     */
308
    public function withPort($port)
309
    {
310
        // TODO: Implement withPort() method.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
311
    }
312
313
    /**
314
     * Return an instance with the specified path.
315
     *
316
     * This method MUST retain the state of the current instance, and return
317
     * an instance that contains the specified path.
318
     *
319
     * The path can either be empty or absolute (starting with a slash) or
320
     * rootless (not starting with a slash). Implementations MUST support all
321
     * three syntaxes.
322
     *
323
     * If the path is intended to be domain-relative rather than path relative then
324
     * it must begin with a slash ("/"). Paths not starting with a slash ("/")
325
     * are assumed to be relative to some base path known to the application or
326
     * consumer.
327
     *
328
     * Users can provide both encoded and decoded path characters.
329
     * Implementations ensure the correct encoding as outlined in getPath().
330
     *
331
     * @param string $path The path to use with the new instance.
332
     * @return static A new instance with the specified path.
0 ignored issues
show
Documentation introduced by
Should the return type not be Uri|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
333
     * @throws \InvalidArgumentException for invalid paths.
334
     */
335
    public function withPath($path)
336
    {
337
        // TODO: Implement withPath() method.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
338
    }
339
340
    /**
341
     * Return an instance with the specified query string.
342
     *
343
     * This method MUST retain the state of the current instance, and return
344
     * an instance that contains the specified query string.
345
     *
346
     * Users can provide both encoded and decoded query characters.
347
     * Implementations ensure the correct encoding as outlined in getQuery().
348
     *
349
     * An empty query string value is equivalent to removing the query string.
350
     *
351
     * @param string $query The query string to use with the new instance.
352
     * @return static A new instance with the specified query string.
0 ignored issues
show
Documentation introduced by
Should the return type not be Uri|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
353
     * @throws \InvalidArgumentException for invalid query strings.
354
     */
355
    public function withQuery($query)
356
    {
357
        // TODO: Implement withQuery() method.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
358
    }
359
360
    /**
361
     * Return an instance with the specified URI fragment.
362
     *
363
     * This method MUST retain the state of the current instance, and return
364
     * an instance that contains the specified URI fragment.
365
     *
366
     * Users can provide both encoded and decoded fragment characters.
367
     * Implementations ensure the correct encoding as outlined in getFragment().
368
     *
369
     * An empty fragment value is equivalent to removing the fragment.
370
     *
371
     * @param string $fragment The fragment to use with the new instance.
372
     * @return static A new instance with the specified fragment.
0 ignored issues
show
Documentation introduced by
Should the return type not be Uri|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
373
     */
374
    public function withFragment($fragment)
375
    {
376
        // TODO: Implement withFragment() method.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
377
    }
378
379
    /**
380
     * Return the string representation as a URI reference.
381
     *
382
     * Depending on which components of the URI are present, the resulting
383
     * string is either a full URI or relative reference according to RFC 3986,
384
     * Section 4.1. The method concatenates the various components of the URI,
385
     * using the appropriate delimiters:
386
     *
387
     * - If a scheme is present, it MUST be suffixed by ":".
388
     * - If an authority is present, it MUST be prefixed by "//".
389
     * - The path can be concatenated without delimiters. But there are two
390
     *   cases where the path has to be adjusted to make the URI reference
391
     *   valid as PHP does not allow to throw an exception in __toString():
392
     *     - If the path is rootless and an authority is present, the path MUST
393
     *       be prefixed by "/".
394
     *     - If the path is starting with more than one "/" and no authority is
395
     *       present, the starting slashes MUST be reduced to one.
396
     * - If a query is present, it MUST be prefixed by "?".
397
     * - If a fragment is present, it MUST be prefixed by "#".
398
     *
399
     * @see http://tools.ietf.org/html/rfc3986#section-4.1
400
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
401
     */
402
    public function __toString()
403
    {
404
        // TODO: Implement __toString() method.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
405
    }
406
407 25
    private function explodeUri($uri)
408
    {
409
        $part_labels            = array(
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 12 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
410 25
            "scheme",
411 25
            "hier_part",
412 25
            "authority",
413 25
            "user_info",
414 25
            "host",
415 25
            "port",
416 25
            "path",
417 25
            "query",
418 25
            "fragment",
419 25
        );
420
421 25
        $reg_start              = '/^';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 14 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
422 25
        $scheme_part            = '(?P<scheme>.+?)';    //Laziness since a URI may contain several colons;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 12 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
423
                                                        //TODO: Refactor to remove laziness
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
424 25
        $scheme_separator       = ':';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 7 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
425 25
        $hier_part              = '(?<hier_part>.[^\?#]+)';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 14 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
426 25
        $query_part             = '(?:\?(?P<query>.[^#]+))?';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 13 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
427 25
        $fragment_part          = '(?:#(?P<fragment>.+))?';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 10 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
428 25
        $reg_end                = '/';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 16 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
429
430
        $uri_syntax             =   $reg_start .
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 13 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
431 25
                                    $scheme_part .
432 25
                                    $scheme_separator .
433 25
                                    $hier_part .
434 25
                                    $query_part .
435 25
                                    $fragment_part .
436 25
                                    $reg_end;
437
438 25
        $uri_valid = preg_match($uri_syntax, $uri, $parts);
0 ignored issues
show
Unused Code introduced by
$uri_valid is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
439
440 25
        foreach ($part_labels as $label) {
441 25
            if (!isset($parts[$label])) {
442 25
                if ($label == "port") {
443 25
                    $parts[$label] = null;
444 25
                } else {
445 25
                    $parts[$label] = "";
446
                }
447 25
            }
448 25
        }
449
450 25
        $hier_parts = $this->explodeHierParts($parts["hier_part"]);
451
452 25
        $parts = array_merge($parts, $hier_parts);
453
454 25
        return $parts;
455
    }
456
457 25
    private function explodeHierParts($hier_part)
458
    {
459 25
        $authority_parts    = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 4 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
460 25
        $hier_parts         = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 9 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
461
462 25
        $reg_start          = '/^';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 10 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
463 25
        $authority_part     = '(?:(?:\/\/)(?P<authority>.[^\/]+))?';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 5 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
464 25
        $path_part          = '(?P<path>.+)';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 10 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
465 25
        $reg_end            = '/';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 12 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
466
467
        $hier_part_syntax   =   $reg_start .
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 3 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
468 25
                                $authority_part .
469 25
                                $path_part .
470 25
                                $reg_end;
471
472 25
        $match              = preg_match($hier_part_syntax, $hier_part, $hier_parts);
0 ignored issues
show
Unused Code introduced by
$match is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 14 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
473
474 25
        if (isset($hier_parts["authority"])) {
475 16
            $authority_parts    = $this->explodeAuthority($hier_parts["authority"]);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 4 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
476 16
        }
477
478 25
        $hier_parts         = array_merge($hier_parts, $authority_parts);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 9 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
479
480 25
        return $hier_parts;
481
    }
482
483 16
    private function explodeAuthority($authority)
484
    {
485 16
        $authority_parts    = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 4 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
486
487 16
        $reg_start          = '/^';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 10 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
488 16
        $user_info_part     = '(?:(?P<user_info>.+)@)?';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 5 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
489 16
        $host_part          = '(?P<host>.[^:]+)';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 10 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
490 16
        $port_part          = '(?::(?P<port>[0-9]+))?';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 10 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
491 16
        $reg_end            = '/';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 12 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
492
493
        $authority_syntax   =   $reg_start .
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 3 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
494 16
                                $user_info_part .
495 16
                                $host_part .
496 16
                                $port_part .
497 16
                                $reg_end;
498
499 16
        $has_authority      = preg_match($authority_syntax, $authority, $authority_parts);
0 ignored issues
show
Unused Code introduced by
$has_authority is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 6 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
500
501 16
        if (isset($authority_parts["port"])) {
502 8
            $authority_parts["port"] = (int) $authority_parts["port"];
503 8
        }
504
505 16
        return $authority_parts;
506
    }
507
}
508