Passed
Push — master ( 7eeee9...32692a )
by Sebastian
15:52
created
src/URLInfo.php 2 patches
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.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
     {
201 201
         $port = $this->getInfoKey('port');
202 202
         
203
-        if(!empty($port)) {
203
+        if (!empty($port)) {
204 204
             return (int)$port;
205 205
         }
206 206
         
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
     
281 281
     protected function getInfoKey(string $name) : string
282 282
     {
283
-        if(isset($this->info[$name])) {
283
+        if (isset($this->info[$name])) {
284 284
             return (string)$this->info[$name];
285 285
         }
286 286
         
@@ -289,11 +289,11 @@  discard block
 block discarded – undo
289 289
 
290 290
     public function getNormalized() : string
291 291
     {
292
-        if(!$this->isValid()) {
292
+        if (!$this->isValid()) {
293 293
             return '';
294 294
         }
295 295
         
296
-        if(!isset($this->normalizer)) {
296
+        if (!isset($this->normalizer)) {
297 297
             $this->normalizer = new URLInfo_Normalizer($this);
298 298
         }
299 299
         
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     */
322 322
     public function getHighlighted() : string
323 323
     {
324
-        if(!$this->isValid()) {
324
+        if (!$this->isValid()) {
325 325
             return '';
326 326
         }
327 327
         
@@ -363,14 +363,14 @@  discard block
 block discarded – undo
363 363
     */
364 364
     public function getParams() : array
365 365
     {
366
-        if(!$this->paramExclusion || empty($this->excludedParams)) {
366
+        if (!$this->paramExclusion || empty($this->excludedParams)) {
367 367
             return $this->info['params'];
368 368
         }
369 369
         
370 370
         $keep = array();
371
-        foreach($this->info['params'] as $name => $value) 
371
+        foreach ($this->info['params'] as $name => $value) 
372 372
         {
373
-            if(!isset($this->excludedParams[$name])) {
373
+            if (!isset($this->excludedParams[$name])) {
374 374
                 $keep[$name] = $value;
375 375
             }
376 376
         }
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
     */
397 397
     public function getParam(string $name) : string
398 398
     {
399
-        if(isset($this->info['params'][$name])) {
399
+        if (isset($this->info['params'][$name])) {
400 400
             return $this->info['params'][$name];
401 401
         }
402 402
         
@@ -415,7 +415,7 @@  discard block
 block discarded – undo
415 415
     */
416 416
     public function excludeParam(string $name, string $reason) : URLInfo
417 417
     {
418
-        if(!isset($this->excludedParams[$name]))
418
+        if (!isset($this->excludedParams[$name]))
419 419
         {
420 420
             $this->excludedParams[$name] = $reason;
421 421
             $this->setParamExclusion();
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
     
442 442
     public function getTypeLabel() : string
443 443
     {
444
-        if(!isset(self::$typeLabels))
444
+        if (!isset(self::$typeLabels))
445 445
         {
446 446
             self::$typeLabels = array(
447 447
                 self::TYPE_EMAIL => t('Email'),
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
         
454 454
         $type = $this->getType();
455 455
         
456
-        if(!isset(self::$typeLabels[$type]))
456
+        if (!isset(self::$typeLabels[$type]))
457 457
         {
458 458
             throw new BaseException(
459 459
                 sprintf('Unknown URL type label for type [%s].', $type),
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
     * @param bool $highlight
474 474
     * @return URLInfo
475 475
     */
476
-    public function setHighlightExcluded(bool $highlight=true) : URLInfo
476
+    public function setHighlightExcluded(bool $highlight = true) : URLInfo
477 477
     {
478 478
         $this->highlightExcluded = $highlight;
479 479
         return $this;
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
      * @see URLInfo::isParamExclusionEnabled()
522 522
      * @see URLInfo::setHighlightExcluded()
523 523
      */
524
-    public function setParamExclusion(bool $enabled=true) : URLInfo
524
+    public function setParamExclusion(bool $enabled = true) : URLInfo
525 525
     {
526 526
         $this->paramExclusion = $enabled;
527 527
         return $this;
@@ -547,13 +547,13 @@  discard block
 block discarded – undo
547 547
     */
548 548
     public function containsExcludedParams() : bool
549 549
     {
550
-        if(empty($this->excludedParams)) {
550
+        if (empty($this->excludedParams)) {
551 551
             return false;
552 552
         }
553 553
         
554 554
         $names = array_keys($this->info['params']);
555
-        foreach($names as $name) {
556
-            if(isset($this->excludedParams[$name])) {
555
+        foreach ($names as $name) {
556
+            if (isset($this->excludedParams[$name])) {
557 557
                 return true;
558 558
             }
559 559
         }
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
 
570 570
     public function offsetSet($offset, $value) 
571 571
     {
572
-        if(in_array($offset, $this->infoKeys)) {
572
+        if (in_array($offset, $this->infoKeys)) {
573 573
             $this->info[$offset] = $value;
574 574
         }
575 575
     }
@@ -586,11 +586,11 @@  discard block
 block discarded – undo
586 586
     
587 587
     public function offsetGet($offset) 
588 588
     {
589
-        if($offset === 'port') {
589
+        if ($offset === 'port') {
590 590
             return $this->getPort();
591 591
         }
592 592
         
593
-        if(in_array($offset, $this->infoKeys)) {
593
+        if (in_array($offset, $this->infoKeys)) {
594 594
             return $this->getInfoKey($offset);
595 595
         }
596 596
         
@@ -623,12 +623,12 @@  discard block
 block discarded – undo
623 623
     * @return bool
624 624
     * @throws BaseException
625 625
     */
626
-    public function tryConnect(bool $verifySSL=true) : bool
626
+    public function tryConnect(bool $verifySSL = true) : bool
627 627
     {
628 628
         requireCURL();
629 629
         
630 630
         $ch = curl_init();
631
-        if($ch === false)
631
+        if ($ch === false)
632 632
         {
633 633
             throw new BaseException(
634 634
                 'Could not initialize a new cURL instance.',
@@ -644,13 +644,13 @@  discard block
 block discarded – undo
644 644
         curl_setopt($ch, CURLOPT_TIMEOUT, 10);
645 645
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
646 646
         
647
-        if(!$verifySSL) 
647
+        if (!$verifySSL) 
648 648
         {
649 649
             curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
650 650
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
651 651
         }
652 652
         
653
-        if($this->hasUsername()) 
653
+        if ($this->hasUsername()) 
654 654
         {
655 655
             curl_setopt($ch, CURLOPT_USERNAME, $this->getUsername());
656 656
             curl_setopt($ch, CURLOPT_PASSWORD, $this->getPassword());
Please login to merge, or discard this patch.