Passed
Push — master ( 7eeee9...32692a )
by Sebastian
15:52
created
src/URLInfo.php 1 patch
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -39,42 +39,42 @@  discard block
 block discarded – undo
39 39
     const TYPE_PHONE = 'phone';
40 40
     const TYPE_URL = 'url';
41 41
     
42
-   /**
43
-    * The original URL that was passed to the constructor.
44
-    * @var string
45
-    */
42
+    /**
43
+     * The original URL that was passed to the constructor.
44
+     * @var string
45
+     */
46 46
     protected $rawURL;
47 47
 
48
-   /**
49
-    * @var array
50
-    */
48
+    /**
49
+     * @var array
50
+     */
51 51
     protected $info;
52 52
     
53
-   /**
54
-    * @var string[]
55
-    */
53
+    /**
54
+     * @var string[]
55
+     */
56 56
     protected $excludedParams = array();
57 57
     
58
-   /**
59
-    * @var bool
60
-    * @see URLInfo::setParamExclusion()
61
-    */
58
+    /**
59
+     * @var bool
60
+     * @see URLInfo::setParamExclusion()
61
+     */
62 62
     protected $paramExclusion = false;
63 63
     
64
-   /**
65
-    * @var array
66
-    * @see URLInfo::getTypeLabel()
67
-    */
64
+    /**
65
+     * @var array
66
+     * @see URLInfo::getTypeLabel()
67
+     */
68 68
     protected static $typeLabels;
69 69
     
70
-   /**
71
-    * @var bool
72
-    */
70
+    /**
71
+     * @var bool
72
+     */
73 73
     protected $highlightExcluded = false;
74 74
     
75
-   /**
76
-    * @var array
77
-    */
75
+    /**
76
+     * @var array
77
+     */
78 78
     protected $infoKeys = array(
79 79
         'scheme',
80 80
         'host',
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
         'fragment'
87 87
     );
88 88
     
89
-   /**
90
-    * @var string
91
-    */
89
+    /**
90
+     * @var string
91
+     */
92 92
     protected $url;
93 93
     
94
-   /**
95
-    * @var URLInfo_Parser
96
-    */
94
+    /**
95
+     * @var URLInfo_Parser
96
+     */
97 97
     protected $parser;
98 98
     
99
-   /**
100
-    * @var URLInfo_Normalizer
101
-    */
99
+    /**
100
+     * @var URLInfo_Normalizer
101
+     */
102 102
     protected $normalizer;
103 103
     
104 104
     public function __construct(string $url)
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
         $this->info = $this->parser->getInfo();
111 111
     }
112 112
     
113
-   /**
114
-    * Filters an URL: removes control characters and the
115
-    * like to have a clean URL to work with.
116
-    * 
117
-    * @param string $url
118
-    * @return string
119
-    */
113
+    /**
114
+     * Filters an URL: removes control characters and the
115
+     * like to have a clean URL to work with.
116
+     * 
117
+     * @param string $url
118
+     * @return string
119
+     */
120 120
     public static function filterURL(string $url)
121 121
     {
122 122
         return URLInfo_Filter::filter($url);
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
         return $this->info['type'] === self::TYPE_PHONE;
147 147
     }
148 148
     
149
-   /**
150
-    * Whether the URL is a regular URL, not one of the 
151
-    * other types like a phone number or email address.
152
-    * 
153
-    * @return bool
154
-    */
149
+    /**
150
+     * Whether the URL is a regular URL, not one of the 
151
+     * other types like a phone number or email address.
152
+     * 
153
+     * @return bool
154
+     */
155 155
     public function isURL() : bool
156 156
     {
157 157
         $host = $this->getHost();
@@ -163,20 +163,20 @@  discard block
 block discarded – undo
163 163
         return $this->parser->isValid();
164 164
     }
165 165
     
166
-   /**
167
-    * Retrieves the host name, or an empty string if none is present.
168
-    * 
169
-    * @return string
170
-    */
166
+    /**
167
+     * Retrieves the host name, or an empty string if none is present.
168
+     * 
169
+     * @return string
170
+     */
171 171
     public function getHost() : string
172 172
     {
173 173
         return $this->getInfoKey('host');
174 174
     }
175 175
     
176
-   /**
177
-    * Retrieves the path, or an empty string if none is present.
178
-    * @return string
179
-    */
176
+    /**
177
+     * Retrieves the path, or an empty string if none is present.
178
+     * @return string
179
+     */
180 180
     public function getPath() : string
181 181
     {
182 182
         return $this->getInfoKey('path');
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
         return $this->getInfoKey('scheme');
193 193
     }
194 194
     
195
-   /**
196
-    * Retrieves the port specified in the URL, or -1 if none is preseent.
197
-    * @return int
198
-    */
195
+    /**
196
+     * Retrieves the port specified in the URL, or -1 if none is preseent.
197
+     * @return int
198
+     */
199 199
     public function getPort() : int
200 200
     {
201 201
         $port = $this->getInfoKey('port');
@@ -207,13 +207,13 @@  discard block
 block discarded – undo
207 207
         return -1;
208 208
     }
209 209
     
210
-   /**
211
-    * Retrieves the raw query string, or an empty string if none is present.
212
-    * 
213
-    * @return string
214
-    * 
215
-    * @see URLInfo::getParams()
216
-    */
210
+    /**
211
+     * Retrieves the raw query string, or an empty string if none is present.
212
+     * 
213
+     * @return string
214
+     * 
215
+     * @see URLInfo::getParams()
216
+     */
217 217
     public function getQuery() : string
218 218
     {
219 219
         return $this->getInfoKey('query');
@@ -229,20 +229,20 @@  discard block
 block discarded – undo
229 229
         return $this->getInfoKey('pass');
230 230
     }
231 231
     
232
-   /**
233
-    * Whether the URL contains a port number.
234
-    * @return bool
235
-    */
232
+    /**
233
+     * Whether the URL contains a port number.
234
+     * @return bool
235
+     */
236 236
     public function hasPort() : bool
237 237
     {
238 238
         return $this->getPort() !== -1;
239 239
     }
240 240
     
241
-   /**
242
-    * Alias for the hasParams() method.
243
-    * @return bool
244
-    * @see URLInfo::hasParams()
245
-    */
241
+    /**
242
+     * Alias for the hasParams() method.
243
+     * @return bool
244
+     * @see URLInfo::hasParams()
245
+     */
246 246
     public function hasQuery() : bool
247 247
     {
248 248
         return $this->hasParams();
@@ -300,25 +300,25 @@  discard block
 block discarded – undo
300 300
         return $this->normalizer->normalize();
301 301
     }
302 302
     
303
-   /**
304
-    * Creates a hash of the URL, which can be used for comparisons.
305
-    * Since any parameters in the URL's query are sorted alphabetically,
306
-    * the same links with a different parameter order will have the 
307
-    * same hash.
308
-    * 
309
-    * @return string
310
-    */
303
+    /**
304
+     * Creates a hash of the URL, which can be used for comparisons.
305
+     * Since any parameters in the URL's query are sorted alphabetically,
306
+     * the same links with a different parameter order will have the 
307
+     * same hash.
308
+     * 
309
+     * @return string
310
+     */
311 311
     public function getHash()
312 312
     {
313 313
         return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized());
314 314
     }
315 315
 
316
-   /**
317
-    * Highlights the URL using HTML tags with specific highlighting
318
-    * class names.
319
-    * 
320
-    * @return string Will return an empty string if the URL is not valid.
321
-    */
316
+    /**
317
+     * Highlights the URL using HTML tags with specific highlighting
318
+     * class names.
319
+     * 
320
+     * @return string Will return an empty string if the URL is not valid.
321
+     */
322 322
     public function getHighlighted() : string
323 323
     {
324 324
         if(!$this->isValid()) {
@@ -352,15 +352,15 @@  discard block
 block discarded – undo
352 352
         return count($params);
353 353
     }
354 354
     
355
-   /**
356
-    * Retrieves all parameters specified in the url,
357
-    * if any, as an associative array. 
358
-    * 
359
-    * NOTE: Ignores parameters that have been added
360
-    * to the excluded parameters list.
361
-    *
362
-    * @return array
363
-    */
355
+    /**
356
+     * Retrieves all parameters specified in the url,
357
+     * if any, as an associative array. 
358
+     * 
359
+     * NOTE: Ignores parameters that have been added
360
+     * to the excluded parameters list.
361
+     *
362
+     * @return array
363
+     */
364 364
     public function getParams() : array
365 365
     {
366 366
         if(!$this->paramExclusion || empty($this->excludedParams)) {
@@ -378,22 +378,22 @@  discard block
 block discarded – undo
378 378
         return $keep;
379 379
     }
380 380
     
381
-   /**
382
-    * Retrieves the names of all parameters present in the URL, if any.
383
-    * @return string[]
384
-    */
381
+    /**
382
+     * Retrieves the names of all parameters present in the URL, if any.
383
+     * @return string[]
384
+     */
385 385
     public function getParamNames() : array
386 386
     {
387 387
         $params = $this->getParams();
388 388
         return array_keys($params);
389 389
     }
390 390
     
391
-   /**
392
-    * Retrieves a specific parameter value from the URL.
393
-    * 
394
-    * @param string $name
395
-    * @return string The parameter value, or an empty string if it does not exist.
396
-    */
391
+    /**
392
+     * Retrieves a specific parameter value from the URL.
393
+     * 
394
+     * @param string $name
395
+     * @return string The parameter value, or an empty string if it does not exist.
396
+     */
397 397
     public function getParam(string $name) : string
398 398
     {
399 399
         if(isset($this->info['params'][$name])) {
@@ -403,16 +403,16 @@  discard block
 block discarded – undo
403 403
         return '';
404 404
     }
405 405
     
406
-   /**
407
-    * Excludes an URL parameter entirely if present:
408
-    * the parser will act as if the parameter was not
409
-    * even present in the source URL, effectively
410
-    * stripping it.
411
-    *
412
-    * @param string $name
413
-    * @param string $reason A human readable explanation why this is excluded - used when highlighting links.
414
-    * @return URLInfo
415
-    */
406
+    /**
407
+     * Excludes an URL parameter entirely if present:
408
+     * the parser will act as if the parameter was not
409
+     * even present in the source URL, effectively
410
+     * stripping it.
411
+     *
412
+     * @param string $name
413
+     * @param string $reason A human readable explanation why this is excluded - used when highlighting links.
414
+     * @return URLInfo
415
+     */
416 416
     public function excludeParam(string $name, string $reason) : URLInfo
417 417
     {
418 418
         if(!isset($this->excludedParams[$name]))
@@ -465,25 +465,25 @@  discard block
 block discarded – undo
465 465
         return self::$typeLabels[$this->getType()];
466 466
     }
467 467
 
468
-   /**
469
-    * Whether excluded parameters should be highlighted in
470
-    * a different color in the URL when using the
471
-    * {@link URLInfo::getHighlighted()} method.
472
-    *
473
-    * @param bool $highlight
474
-    * @return URLInfo
475
-    */
468
+    /**
469
+     * Whether excluded parameters should be highlighted in
470
+     * a different color in the URL when using the
471
+     * {@link URLInfo::getHighlighted()} method.
472
+     *
473
+     * @param bool $highlight
474
+     * @return URLInfo
475
+     */
476 476
     public function setHighlightExcluded(bool $highlight=true) : URLInfo
477 477
     {
478 478
         $this->highlightExcluded = $highlight;
479 479
         return $this;
480 480
     }
481 481
     
482
-   /**
483
-    * Returns an array with all relevant URL information.
484
-    * 
485
-    * @return array
486
-    */
482
+    /**
483
+     * Returns an array with all relevant URL information.
484
+     * 
485
+     * @return array
486
+     */
487 487
     public function toArray() : array
488 488
     {
489 489
         return array(
@@ -527,24 +527,24 @@  discard block
 block discarded – undo
527 527
         return $this;
528 528
     }
529 529
     
530
-   /**
531
-    * Whether the parameter exclusion mode is enabled:
532
-    * In this case, if any parameters have been added to the
533
-    * exclusion list, all relevant methods will exclude these.
534
-    *
535
-    * @return bool
536
-    */
530
+    /**
531
+     * Whether the parameter exclusion mode is enabled:
532
+     * In this case, if any parameters have been added to the
533
+     * exclusion list, all relevant methods will exclude these.
534
+     *
535
+     * @return bool
536
+     */
537 537
     public function isParamExclusionEnabled() : bool
538 538
     {
539 539
         return $this->paramExclusion;
540 540
     }
541 541
     
542
-   /**
543
-    * Checks whether the link contains any parameters that
544
-    * are on the list of excluded parameters.
545
-    *
546
-    * @return bool
547
-    */
542
+    /**
543
+     * Checks whether the link contains any parameters that
544
+     * are on the list of excluded parameters.
545
+     *
546
+     * @return bool
547
+     */
548 548
     public function containsExcludedParams() : bool
549 549
     {
550 550
         if(empty($this->excludedParams)) {
@@ -612,17 +612,17 @@  discard block
 block discarded – undo
612 612
         return $this->highlightExcluded;
613 613
     }
614 614
     
615
-   /**
616
-    * Checks if the URL exists, i.e. can be connected to. Will return
617
-    * true if the returned HTTP status code is `200` or `302`.
618
-    * 
619
-    * NOTE: If the target URL requires HTTP authentication, the username
620
-    * and password should be integrated into the URL.
621
-    * 
622
-    * @param bool $verifySSL Whether to enable SSL certificate checks. Warning: do not use this in production.
623
-    * @return bool
624
-    * @throws BaseException
625
-    */
615
+    /**
616
+     * Checks if the URL exists, i.e. can be connected to. Will return
617
+     * true if the returned HTTP status code is `200` or `302`.
618
+     * 
619
+     * NOTE: If the target URL requires HTTP authentication, the username
620
+     * and password should be integrated into the URL.
621
+     * 
622
+     * @param bool $verifySSL Whether to enable SSL certificate checks. Warning: do not use this in production.
623
+     * @return bool
624
+     * @throws BaseException
625
+     */
626 626
     public function tryConnect(bool $verifySSL=true) : bool
627 627
     {
628 628
         requireCURL();
Please login to merge, or discard this patch.