Passed
Push — master ( 707ddf...aa8b2f )
by Sebastian
04:56
created
src/ConvertHelper/URLFinder/Detector/HTMLAttributes.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,9 +43,9 @@
 block discarded – undo
43 43
 
44 44
         $result = array();
45 45
         $matches = array_unique($matches[2]);
46
-        foreach($matches as $match) {
46
+        foreach ($matches as $match) {
47 47
             $match = trim($match);
48
-            if(!empty($match) && !in_array($match, $result)) {
48
+            if (!empty($match) && !in_array($match, $result)) {
49 49
                 $result[] = $match;
50 50
             }
51 51
         }
Please login to merge, or discard this patch.
src/ConvertHelper/URLFinder/DomainExtensions.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 
35 35
     public function __construct()
36 36
     {
37
-        if(empty(self::$cacheFile)) {
37
+        if (empty(self::$cacheFile)) {
38 38
             self::$cacheFile = __DIR__.'/tlds-alpha-by-domain.txt';
39 39
         }
40 40
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 
59 59
     private function load() : void
60 60
     {
61
-        if(!empty(self::$names)) {
61
+        if (!empty(self::$names)) {
62 62
             return;
63 63
         }
64 64
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 
69 69
         // Store the names as keys in the array to allow
70 70
         // faster lookups (to avoid using in_array).
71
-        foreach($names as $name) {
71
+        foreach ($names as $name) {
72 72
             self::$names[$name] = '';
73 73
         }
74 74
     }
Please login to merge, or discard this patch.
src/ConvertHelper/URLFinder.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -110,38 +110,38 @@  discard block
 block discarded – undo
110 110
         return $this;
111 111
     }
112 112
     
113
-   /**
114
-    * Whether to enable sorting the URLs alphabetically (disabled by default).
115
-    * 
116
-    * @param bool $enabled
117
-    * @return $this
118
-    */
113
+    /**
114
+     * Whether to enable sorting the URLs alphabetically (disabled by default).
115
+     * 
116
+     * @param bool $enabled
117
+     * @return $this
118
+     */
119 119
     public function enableSorting(bool $enabled=true) : ConvertHelper_URLFinder
120 120
     {
121 121
         $this->setOption('sorting', $enabled);
122 122
         return $this;
123 123
     }
124 124
     
125
-   /**
126
-    * Whether to include email addresses in the search. 
127
-    * This is only relevant when using the getURLs()
128
-    * method.
129
-    * 
130
-    * @param bool $include
131
-    * @return ConvertHelper_URLFinder
132
-    */
125
+    /**
126
+     * Whether to include email addresses in the search. 
127
+     * This is only relevant when using the getURLs()
128
+     * method.
129
+     * 
130
+     * @param bool $include
131
+     * @return ConvertHelper_URLFinder
132
+     */
133 133
     public function includeEmails(bool $include=true) : ConvertHelper_URLFinder
134 134
     {
135 135
         $this->setOption('include-emails', $include);
136 136
         return $this;
137 137
     }
138 138
     
139
-   /**
140
-    * Whether to omit the mailto: that is automatically added to all email addresses.
141
-    * 
142
-    * @param bool $omit
143
-    * @return ConvertHelper_URLFinder
144
-    */
139
+    /**
140
+     * Whether to omit the mailto: that is automatically added to all email addresses.
141
+     * 
142
+     * @param bool $omit
143
+     * @return ConvertHelper_URLFinder
144
+     */
145 145
     public function omitMailto(bool $omit=true) : ConvertHelper_URLFinder
146 146
     {
147 147
         $this->setOption('omit-mailto', $omit);
@@ -267,11 +267,11 @@  discard block
 block discarded – undo
267 267
         );
268 268
     }
269 269
 
270
-   /**
271
-    * Fetches all URLs that can be found in the subject string.
272
-    * 
273
-    * @return string[]
274
-    */
270
+    /**
271
+     * Fetches all URLs that can be found in the subject string.
272
+     * 
273
+     * @return string[]
274
+     */
275 275
     public function getURLs() : array
276 276
     {
277 277
         $this->parse();
@@ -474,13 +474,13 @@  discard block
 block discarded – undo
474 474
         return array_pop($parts);
475 475
     }
476 476
 
477
-   /**
478
-    * Retrieves all email addresses from the subject string.
479
-    * 
480
-    * @return string[]
481
-    * 
482
-    * @see omitMailto()
483
-    */
477
+    /**
478
+     * Retrieves all email addresses from the subject string.
479
+     * 
480
+     * @return string[]
481
+     * 
482
+     * @see omitMailto()
483
+     */
484 484
     public function getEmails() : array
485 485
     {
486 486
         $this->parse();
@@ -506,11 +506,11 @@  discard block
 block discarded – undo
506 506
         return $result;
507 507
     }
508 508
     
509
-   /**
510
-    * Retrieves all URLs as URLInfo instances.
511
-    * 
512
-    * @return URLInfo[]
513
-    */
509
+    /**
510
+     * Retrieves all URLs as URLInfo instances.
511
+     * 
512
+     * @return URLInfo[]
513
+     */
514 514
     public function getInfos() : array
515 515
     {
516 516
         $this->parse();
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
      * @param bool $enabled
105 105
      * @return $this
106 106
      */
107
-    public function enableNormalizing(bool $enabled=true) : ConvertHelper_URLFinder
107
+    public function enableNormalizing(bool $enabled = true) : ConvertHelper_URLFinder
108 108
     {
109 109
         $this->setOption('normalize', $enabled);
110 110
         return $this;
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
     * @param bool $enabled
117 117
     * @return $this
118 118
     */
119
-    public function enableSorting(bool $enabled=true) : ConvertHelper_URLFinder
119
+    public function enableSorting(bool $enabled = true) : ConvertHelper_URLFinder
120 120
     {
121 121
         $this->setOption('sorting', $enabled);
122 122
         return $this;
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
     * @param bool $include
131 131
     * @return ConvertHelper_URLFinder
132 132
     */
133
-    public function includeEmails(bool $include=true) : ConvertHelper_URLFinder
133
+    public function includeEmails(bool $include = true) : ConvertHelper_URLFinder
134 134
     {
135 135
         $this->setOption('include-emails', $include);
136 136
         return $this;
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
     * @param bool $omit
143 143
     * @return ConvertHelper_URLFinder
144 144
     */
145
-    public function omitMailto(bool $omit=true) : ConvertHelper_URLFinder
145
+    public function omitMailto(bool $omit = true) : ConvertHelper_URLFinder
146 146
     {
147 147
         $this->setOption('omit-mailto', $omit);
148 148
         return $this;
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         {
170 170
             $line = $this->analyzeLine($line);
171 171
 
172
-            if($line !== null) {
172
+            if ($line !== null) {
173 173
                 $keep[] = $line;
174 174
             }
175 175
         }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         $line = trim($line, '.');
191 191
 
192 192
         // Handle detecting an URI scheme
193
-        if(strstr($line, ':') !== false)
193
+        if (strstr($line, ':') !== false)
194 194
         {
195 195
             $scheme = URLInfo_Schemes::detectScheme($line);
196 196
 
@@ -204,12 +204,12 @@  discard block
 block discarded – undo
204 204
         // detect are email addresses and domain names.
205 205
 
206 206
         // No dot? Then it's certainly not a domain name.
207
-        if(strstr($line, '.') === false) {
207
+        if (strstr($line, '.') === false) {
208 208
             return null;
209 209
         }
210 210
 
211 211
         // Check again if there are still dots present
212
-        if(strstr($line, '.') !== false) {
212
+        if (strstr($line, '.') !== false) {
213 213
             return $line;
214 214
         }
215 215
 
@@ -227,10 +227,10 @@  discard block
 block discarded – undo
227 227
     {
228 228
         $subject = stripslashes($subject);
229 229
 
230
-        foreach($this->detectors as $detector)
230
+        foreach ($this->detectors as $detector)
231 231
         {
232 232
             // Avoid processing the string if it is not needed.
233
-            if($detector->getRunPosition() !== ConvertHelper_URLFinder_Detector::RUN_BEFORE || !$detector->isValidFor($subject)) {
233
+            if ($detector->getRunPosition() !== ConvertHelper_URLFinder_Detector::RUN_BEFORE || !$detector->isValidFor($subject)) {
234 234
                 continue;
235 235
             }
236 236
 
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
     {
252 252
         $detector = new $className();
253 253
 
254
-        if($detector instanceof ConvertHelper_URLFinder_Detector)
254
+        if ($detector instanceof ConvertHelper_URLFinder_Detector)
255 255
         {
256 256
             return $detector;
257 257
         }
@@ -278,12 +278,12 @@  discard block
 block discarded – undo
278 278
 
279 279
         $result = $this->getItemsAsString($this->urls);
280 280
 
281
-        if($this->getBoolOption('include-emails'))
281
+        if ($this->getBoolOption('include-emails'))
282 282
         {
283 283
             $result = array_merge($result, $this->getEmails());
284 284
         }
285 285
 
286
-        if($this->getBoolOption('sorting'))
286
+        if ($this->getBoolOption('sorting'))
287 287
         {
288 288
             usort($result, function(string $a, string $b) {
289 289
                 return strnatcasecmp($a, $b);
@@ -303,12 +303,12 @@  discard block
 block discarded – undo
303 303
 
304 304
         $result = array();
305 305
 
306
-        foreach($collection as $url => $info) {
307
-            if($normalize) {
306
+        foreach ($collection as $url => $info) {
307
+            if ($normalize) {
308 308
                 $url = $info->getNormalized();
309 309
             }
310 310
 
311
-            if(!in_array($url, $result)) {
311
+            if (!in_array($url, $result)) {
312 312
                 $result[] = $url;
313 313
             }
314 314
         }
@@ -325,9 +325,9 @@  discard block
 block discarded – undo
325 325
      */
326 326
     private function initDetectors() : void
327 327
     {
328
-        foreach($this->enabledDetectorClasses as $className => $enabled)
328
+        foreach ($this->enabledDetectorClasses as $className => $enabled)
329 329
         {
330
-            if($enabled) {
330
+            if ($enabled) {
331 331
                 $this->detectors[] = $this->createDetector($className);
332 332
             }
333 333
         }
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      */
343 343
     private function parse() : void
344 344
     {
345
-        if($this->parsed) {
345
+        if ($this->parsed) {
346 346
             return;
347 347
         }
348 348
 
@@ -353,11 +353,11 @@  discard block
 block discarded – undo
353 353
 
354 354
         unset($this->subject);
355 355
 
356
-        foreach($this->matches as $match)
356
+        foreach ($this->matches as $match)
357 357
         {
358 358
             $info = parseURL($match);
359 359
 
360
-            if($info->isEmail())
360
+            if ($info->isEmail())
361 361
             {
362 362
                 $this->emails[$this->filterEmailAddress($match)] = $info;
363 363
                 continue;
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
      * @param bool $enable
374 374
      * @return $this
375 375
      */
376
-    public function enableHTMLAttributes(bool $enable=true) : ConvertHelper_URLFinder
376
+    public function enableHTMLAttributes(bool $enable = true) : ConvertHelper_URLFinder
377 377
     {
378 378
         $this->enabledDetectorClasses[ConvertHelper_URLFinder_Detector_HTMLAttributes::class] = $enable;
379 379
         return $this;
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
      */
389 389
     private function filterEmailAddress(string $email) : string
390 390
     {
391
-        if(stristr($email, 'mailto:') === false) {
391
+        if (stristr($email, 'mailto:') === false) {
392 392
             $email = 'mailto:'.$email;
393 393
         }
394 394
 
@@ -410,14 +410,14 @@  discard block
 block discarded – undo
410 410
         foreach ($lines as $line)
411 411
         {
412 412
             $scheme = URLInfo_Schemes::detectScheme($line);
413
-            if($scheme !== null) {
413
+            if ($scheme !== null) {
414 414
                 $this->matches[] = $line;
415 415
                 continue;
416 416
             }
417 417
 
418 418
             $extension = $this->detectDomainExtension($line);
419 419
 
420
-            if($domains->nameExists($extension)) {
420
+            if ($domains->nameExists($extension)) {
421 421
                 $this->matches[] = $line;
422 422
             }
423 423
         }
@@ -436,9 +436,9 @@  discard block
 block discarded – undo
436 436
 
437 437
         $subject = str_replace($remove, ' ', $subject);
438 438
 
439
-        foreach($this->detectors as $detector)
439
+        foreach ($this->detectors as $detector)
440 440
         {
441
-            if($detector->getRunPosition() !== ConvertHelper_URLFinder_Detector::RUN_AFTER || !$detector->isValidFor($subject)) {
441
+            if ($detector->getRunPosition() !== ConvertHelper_URLFinder_Detector::RUN_AFTER || !$detector->isValidFor($subject)) {
442 442
                 continue;
443 443
             }
444 444
 
@@ -461,8 +461,8 @@  discard block
 block discarded – undo
461 461
         $boundaries = array('/', '?');
462 462
 
463 463
         // Remove the path or query parts to access the domain extension only
464
-        foreach($boundaries as $boundary) {
465
-            if(strstr($url, $boundary)) {
464
+        foreach ($boundaries as $boundary) {
465
+            if (strstr($url, $boundary)) {
466 466
                 $parts = explode($boundary, $url);
467 467
                 $url = array_shift($parts);
468 468
                 break;
@@ -487,16 +487,16 @@  discard block
 block discarded – undo
487 487
 
488 488
         $result = $this->getItemsAsString($this->emails);
489 489
 
490
-        if($this->getBoolOption('omit-mailto')) {
490
+        if ($this->getBoolOption('omit-mailto')) {
491 491
             $keep = array();
492
-            foreach($result as $email) {
492
+            foreach ($result as $email) {
493 493
                 $keep[] = str_replace('mailto:', '', $email);
494 494
             }
495 495
 
496 496
             $result = $keep;
497 497
         }
498 498
 
499
-        if($this->getBoolOption('sorting'))
499
+        if ($this->getBoolOption('sorting'))
500 500
         {
501 501
             usort($result, function(string $a, string $b) {
502 502
                 return strnatcasecmp($a, $b);
@@ -518,16 +518,16 @@  discard block
 block discarded – undo
518 518
         $result = array();
519 519
         $normalize = $this->getBoolOption('normalize');
520 520
 
521
-        foreach($this->urls as $url => $info)
521
+        foreach ($this->urls as $url => $info)
522 522
         {
523
-            if($normalize) {
523
+            if ($normalize) {
524 524
                 $url = $info->getNormalized();
525 525
             }
526 526
 
527 527
             $result[$url] = $info;
528 528
         }
529 529
 
530
-        if($this->getBoolOption('sorting'))
530
+        if ($this->getBoolOption('sorting'))
531 531
         {
532 532
             ksort($result);
533 533
         }
Please login to merge, or discard this patch.
src/NumberInfo.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function setValue($value) : NumberInfo
86 86
     {
87
-        if($value instanceof NumberInfo) {
87
+        if ($value instanceof NumberInfo) {
88 88
             $value = $value->getValue();
89 89
         }
90 90
         
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
     
118 118
     public function isPositive() : bool
119 119
     {
120
-        if(!$this->isEmpty()) {
120
+        if (!$this->isEmpty()) {
121 121
             $number = $this->getNumber();
122 122
             return $number > 0;
123 123
         }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
      */
133 133
     public function isZero() : bool
134 134
     {
135
-        if($this->isEmpty()) {
135
+        if ($this->isEmpty()) {
136 136
             return false;
137 137
         }
138 138
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function hasValue() : bool
154 154
     {
155
-        if(!$this->isEmpty() && !$this->isZero()) {
155
+        if (!$this->isEmpty() && !$this->isZero()) {
156 156
             return true;
157 157
         }
158 158
         
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
     {
207 207
         $number = (float)$this->info['number'];
208 208
 
209
-        if($this->hasDecimals()) {
209
+        if ($this->hasDecimals()) {
210 210
             return $number;
211 211
         }
212 212
 
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
      */
239 239
     public function getUnits()
240 240
     {
241
-        if($this->isEmpty()) {
241
+        if ($this->isEmpty()) {
242 242
             return '';
243 243
         }
244 244
 
245
-        if(!$this->hasUnits()) {
245
+        if (!$this->hasUnits()) {
246 246
             return 'px';
247 247
         }
248 248
         
@@ -276,15 +276,15 @@  discard block
 block discarded – undo
276 276
      */
277 277
     public function toAttribute() : string
278 278
     {
279
-        if($this->isEmpty()) {
279
+        if ($this->isEmpty()) {
280 280
             return '';
281 281
         }
282 282
         
283
-        if($this->isZero()) {
283
+        if ($this->isZero()) {
284 284
             return '0';
285 285
         }
286 286
         
287
-        if($this->isPercent()) {
287
+        if ($this->isPercent()) {
288 288
             return $this->getNumber().$this->getUnits();
289 289
         }
290 290
         
@@ -297,11 +297,11 @@  discard block
 block discarded – undo
297 297
      */
298 298
     public function toCSS() : string
299 299
     {
300
-        if($this->isEmpty()) {
300
+        if ($this->isEmpty()) {
301 301
             return '';
302 302
         }
303 303
         
304
-        if($this->isZero()) {
304
+        if ($this->isZero()) {
305 305
             return '0';
306 306
         }
307 307
         
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
     
311 311
     public function __toString()
312 312
     {
313
-        if($this->isEmpty()) {
313
+        if ($this->isEmpty()) {
314 314
             return '';
315 315
         }
316 316
         
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
     public function isBiggerThan($number)
329 329
     {
330 330
         $number = parseNumber($number);
331
-        if($number->getUnits() != $this->getUnits()) {
331
+        if ($number->getUnits() != $this->getUnits()) {
332 332
             return false;
333 333
         }
334 334
         
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
     public function isSmallerThan($number)
347 347
     {
348 348
         $number = parseNumber($number);
349
-        if($number->getUnits() != $this->getUnits()) {
349
+        if ($number->getUnits() != $this->getUnits()) {
350 350
             return false;
351 351
         }
352 352
         
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
     public function isBiggerEqual($number)
357 357
     {
358 358
         $number = parseNumber($number);
359
-        if($number->getUnits() != $this->getUnits()) {
359
+        if ($number->getUnits() != $this->getUnits()) {
360 360
             return false;
361 361
         }
362 362
         
@@ -373,14 +373,14 @@  discard block
 block discarded – undo
373 373
      */
374 374
     public function add($value)
375 375
     {
376
-        if($this->isEmpty()) {
376
+        if ($this->isEmpty()) {
377 377
             $this->setValue($value);
378 378
             return $this;
379 379
         }
380 380
         
381 381
         $number = parseNumber($value);
382 382
         
383
-        if($number->getUnits() == $this->getUnits() || !$number->hasUnits())
383
+        if ($number->getUnits() == $this->getUnits() || !$number->hasUnits())
384 384
         {
385 385
             $new = $this->getNumber() + $number->getNumber();
386 386
             $this->setValue($new.$this->getUnits());
@@ -399,14 +399,14 @@  discard block
 block discarded – undo
399 399
      */
400 400
     public function subtract($value)
401 401
     {
402
-        if($this->isEmpty()) {
402
+        if ($this->isEmpty()) {
403 403
             $this->setValue($value);
404 404
             return $this;
405 405
         }
406 406
         
407 407
         $number = parseNumber($value);
408 408
         
409
-        if($number->getUnits() == $this->getUnits() || !$number->hasUnits())
409
+        if ($number->getUnits() == $this->getUnits() || !$number->hasUnits())
410 410
         {
411 411
             $new = $this->getNumber() - $number->getNumber();
412 412
             $this->setValue($new.$this->getUnits());
@@ -433,25 +433,25 @@  discard block
 block discarded – undo
433 433
     
434 434
     protected function percentOperation($operation, $percent)
435 435
     {
436
-        if($this->isZeroOrEmpty()) {
436
+        if ($this->isZeroOrEmpty()) {
437 437
             return $this;
438 438
         }
439 439
         
440 440
         $percent = parseNumber($percent);
441
-        if($percent->hasUnits() && !$percent->isPercent()) {
441
+        if ($percent->hasUnits() && !$percent->isPercent()) {
442 442
             return $this;
443 443
         }
444 444
         
445 445
         $number = $this->getNumber();
446 446
         $value = $number * $percent->getNumber() / 100;
447 447
         
448
-        if($operation == '-') {
448
+        if ($operation == '-') {
449 449
             $number = $number - $value;
450 450
         } else {
451 451
             $number = $number + $value;
452 452
         }
453 453
         
454
-        if($this->isUnitInteger()) {
454
+        if ($this->isUnitInteger()) {
455 455
             $number = intval($number);
456 456
         }
457 457
         
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
         
503 503
         $key = $this->createValueKey($value);
504 504
 
505
-        if(array_key_exists($key, $cache)) {
505
+        if (array_key_exists($key, $cache)) {
506 506
             return $cache[$key];
507 507
         }
508 508
         
@@ -512,13 +512,13 @@  discard block
 block discarded – undo
512 512
             'number' => null
513 513
         );
514 514
         
515
-        if($key === '_EMPTY_') 
515
+        if ($key === '_EMPTY_') 
516 516
         {
517 517
             $cache[$key]['empty'] = true;
518 518
             return $cache[$key];
519 519
         }
520 520
         
521
-        if($value === 0 || $value === '0') 
521
+        if ($value === 0 || $value === '0') 
522 522
         {
523 523
             $cache[$key]['number'] = 0;
524 524
             $cache[$key] = $this->filterInfo($cache[$key]);
@@ -527,20 +527,20 @@  discard block
 block discarded – undo
527 527
         
528 528
         $test = trim((string)$value);
529 529
         
530
-        if($test === '') 
530
+        if ($test === '') 
531 531
         {
532 532
             $cache[$key]['empty'] = true;
533 533
             return $cache[$key];
534 534
         }
535 535
         
536 536
         // replace comma notation (which is only possible if it's a string)
537
-        if(is_string($value))
537
+        if (is_string($value))
538 538
         {
539 539
             $test = $this->preProcess($test, $cache, $value);
540 540
         }
541 541
         
542 542
         // convert to a number if it's numeric
543
-        if(is_numeric($test)) 
543
+        if (is_numeric($test)) 
544 544
         {
545 545
             $cache[$key]['number'] = (float)$test * 1;
546 546
             $cache[$key] = $this->filterInfo($cache[$key]);
@@ -566,19 +566,19 @@  discard block
 block discarded – undo
566 566
         $empty = false;
567 567
         
568 568
         $found = $this->findUnits($test);
569
-        if($found !== null) 
569
+        if ($found !== null) 
570 570
         {
571 571
             $number = $found['number'];
572 572
             $units = $found['units'];
573 573
         }
574 574
         
575 575
         // the filters have to restore the value
576
-        if($this->postProcess)
576
+        if ($this->postProcess)
577 577
         {
578 578
             $number = $this->postProcess($number, $test);
579 579
         }
580 580
         // empty number
581
-        else if($number === '' || $number === null || is_bool($number))
581
+        else if ($number === '' || $number === null || is_bool($number))
582 582
         {
583 583
             $number = null;
584 584
             $empty = true;
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
             $number = trim($number);
590 590
             
591 591
             // may be an arbitrary string in some cases
592
-            if(!is_numeric($number))
592
+            if (!is_numeric($number))
593 593
             {
594 594
                 $number = null;
595 595
                 $empty = true;
@@ -621,17 +621,17 @@  discard block
 block discarded – undo
621 621
         $vlength = strlen($value);
622 622
         $names = array_keys($this->knownUnits);
623 623
         
624
-        foreach($names as $unit)
624
+        foreach ($names as $unit)
625 625
         {
626 626
             $ulength = strlen($unit);
627
-            $start = $vlength-$ulength;
628
-            if($start < 0) {
627
+            $start = $vlength - $ulength;
628
+            if ($start < 0) {
629 629
                 continue;
630 630
             }
631 631
             
632 632
             $search = substr($value, $start, $ulength);
633 633
             
634
-            if($search==$unit) 
634
+            if ($search == $unit) 
635 635
             {
636 636
                 return array(
637 637
                     'units' => $unit,
@@ -651,7 +651,7 @@  discard block
 block discarded – undo
651 651
     */
652 652
     private function createValueKey($value) : string
653 653
     {
654
-        if(!is_string($value) && !is_numeric($value))
654
+        if (!is_string($value) && !is_numeric($value))
655 655
         {
656 656
             return '_EMPTY_';
657 657
         }
@@ -717,12 +717,12 @@  discard block
 block discarded – undo
717 717
     protected function filterInfo(array $info) : array
718 718
     {
719 719
         $useUnits = 'px';
720
-        if($info['units'] !== null) {
720
+        if ($info['units'] !== null) {
721 721
             $useUnits = $info['units'];
722 722
         }
723 723
         
724 724
         // the units are non-decimal: convert decimal values
725
-        if($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number']))
725
+        if ($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number']))
726 726
         {
727 727
             $info['number'] = intval($info['number']);
728 728
         }
Please login to merge, or discard this patch.
src/URLInfo/Parser.php 3 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -23,24 +23,24 @@  discard block
 block discarded – undo
23 23
  */
24 24
 class URLInfo_Parser
25 25
 {
26
-   /**
27
-    * @var string
28
-    */
26
+    /**
27
+     * @var string
28
+     */
29 29
     protected $url;
30 30
     
31
-   /**
32
-    * @var bool
33
-    */
31
+    /**
32
+     * @var bool
33
+     */
34 34
     protected $isValid = false;
35 35
     
36
-   /**
37
-    * @var array
38
-    */
36
+    /**
37
+     * @var array
38
+     */
39 39
     protected $info;
40 40
     
41
-   /**
42
-    * @var array|NULL
43
-    */
41
+    /**
42
+     * @var array|NULL
43
+     */
44 44
     protected $error;
45 45
     
46 46
     /**
@@ -57,25 +57,25 @@  discard block
 block discarded – undo
57 57
         'git'
58 58
     );
59 59
     
60
-   /**
61
-    * Stores a list of all unicode characters in the URL
62
-    * that have been filtered out before parsing it with
63
-    * parse_url.
64
-    * 
65
-    * @var string[]string
66
-    */
60
+    /**
61
+     * Stores a list of all unicode characters in the URL
62
+     * that have been filtered out before parsing it with
63
+     * parse_url.
64
+     * 
65
+     * @var string[]string
66
+     */
67 67
     protected $unicodeChars = array();
68 68
     
69
-   /**
70
-    * @var bool
71
-    */
69
+    /**
70
+     * @var bool
71
+     */
72 72
     protected $encodeUTF = false;
73 73
     
74
-   /**
75
-    * 
76
-    * @param string $url The target URL.
77
-    * @param bool $encodeUTF Whether to URL encode any plain text unicode characters.
78
-    */
74
+    /**
75
+     * 
76
+     * @param string $url The target URL.
77
+     * @param bool $encodeUTF Whether to URL encode any plain text unicode characters.
78
+     */
79 79
     public function __construct(string $url, bool $encodeUTF)
80 80
     {
81 81
         $this->url = $url;
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
         }
89 89
     }
90 90
 
91
-   /**
92
-    * Retrieves the array as parsed by PHP's parse_url,
93
-    * filtered and adjusted as necessary.
94
-    * 
95
-    * @return array
96
-    */
91
+    /**
92
+     * Retrieves the array as parsed by PHP's parse_url,
93
+     * filtered and adjusted as necessary.
94
+     * 
95
+     * @return array
96
+     */
97 97
     public function getInfo() : array
98 98
     {
99 99
         return $this->info;
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
         }
116 116
     }
117 117
 
118
-   /**
119
-    * Finds any non-url encoded unicode characters in 
120
-    * the URL, and encodes them before the URL is 
121
-    * passed to parse_url.
122
-    */
118
+    /**
119
+     * Finds any non-url encoded unicode characters in 
120
+     * the URL, and encodes them before the URL is 
121
+     * passed to parse_url.
122
+     */
123 123
     protected function filterUnicodeChars() : void
124 124
     {
125 125
         $chars = ConvertHelper::string2array($this->url);
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
         return false;
239 239
     }
240 240
 
241
-   /**
242
-    * Goes through all information in the parse_url result
243
-    * array, and attempts to fix any user errors in formatting
244
-    * that can be recovered from, mostly regarding stray spaces.
245
-    */
241
+    /**
242
+     * Goes through all information in the parse_url result
243
+     * array, and attempts to fix any user errors in formatting
244
+     * that can be recovered from, mostly regarding stray spaces.
245
+     */
246 246
     protected function filterParsed() : void
247 247
     {
248 248
         $this->info['params'] = array();
@@ -284,13 +284,13 @@  discard block
 block discarded – undo
284 284
         }
285 285
     }
286 286
     
287
-   /**
288
-    * Recursively goes through the array, and converts all previously
289
-    * URL encoded characters with their unicode character counterparts.
290
-    * 
291
-    * @param array $subject
292
-    * @return array
293
-    */
287
+    /**
288
+     * Recursively goes through the array, and converts all previously
289
+     * URL encoded characters with their unicode character counterparts.
290
+     * 
291
+     * @param array $subject
292
+     * @return array
293
+     */
294 294
     protected function restoreUnicodeChars(array $subject) : array
295 295
     {
296 296
         $result = array();
@@ -314,13 +314,13 @@  discard block
 block discarded – undo
314 314
         return $result;
315 315
     }
316 316
     
317
-   /**
318
-    * Replaces all URL encoded unicode characters
319
-    * in the string with the unicode character.
320
-    * 
321
-    * @param string $string
322
-    * @return string
323
-    */
317
+    /**
318
+     * Replaces all URL encoded unicode characters
319
+     * in the string with the unicode character.
320
+     * 
321
+     * @param string $string
322
+     * @return string
323
+     */
324 324
     protected function restoreUnicodeChar(string $string) : string
325 325
     {
326 326
         if(strstr($string, '%'))
@@ -404,21 +404,21 @@  discard block
 block discarded – undo
404 404
         );
405 405
     }
406 406
    
407
-   /**
408
-    * Checks whether the URL that was parsed is valid.
409
-    * @return bool
410
-    */
407
+    /**
408
+     * Checks whether the URL that was parsed is valid.
409
+     * @return bool
410
+     */
411 411
     public function isValid() : bool
412 412
     {
413 413
         return $this->isValid;
414 414
     }
415 415
 
416
-   /**
417
-    * If the validation failed, retrieves the validation
418
-    * error message.
419
-    * 
420
-    * @return string
421
-    */
416
+    /**
417
+     * If the validation failed, retrieves the validation
418
+     * error message.
419
+     * 
420
+     * @return string
421
+     */
422 422
     public function getErrorMessage() : string
423 423
     {
424 424
         if(isset($this->error)) {
@@ -428,12 +428,12 @@  discard block
 block discarded – undo
428 428
         return '';
429 429
     }
430 430
     
431
-   /**
432
-    * If the validation failed, retrieves the validation
433
-    * error code.
434
-    * 
435
-    * @return int
436
-    */
431
+    /**
432
+     * If the validation failed, retrieves the validation
433
+     * error code.
434
+     * 
435
+     * @return int
436
+     */
437 437
     public function getErrorCode() : int
438 438
     {
439 439
         if(isset($this->error)) {
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
         
84 84
         $this->parse();
85 85
         
86
-        if(!$this->detectType()) {
86
+        if (!$this->detectType()) {
87 87
             $this->validate();
88 88
         }
89 89
     }
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
         
110 110
         // if the URL contains any URL characters, and we
111 111
         // do not want them URL encoded, restore them.
112
-        if(!$this->encodeUTF && !empty($this->unicodeChars))
112
+        if (!$this->encodeUTF && !empty($this->unicodeChars))
113 113
         {
114 114
             $this->info = $this->restoreUnicodeChars($this->info);
115 115
         }
@@ -126,13 +126,13 @@  discard block
 block discarded – undo
126 126
         
127 127
         $keep = array();
128 128
         
129
-        foreach($chars as $char)
129
+        foreach ($chars as $char)
130 130
         {
131
-            if(preg_match('/\p{L}/usix', $char))
131
+            if (preg_match('/\p{L}/usix', $char))
132 132
             {
133 133
                 $encoded = rawurlencode($char);
134 134
                 
135
-                if($encoded != $char)
135
+                if ($encoded != $char)
136 136
                 {
137 137
                     $this->unicodeChars[$encoded] = $char;
138 138
                     $char = $encoded;
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
             'ipAddress'
155 155
         );
156 156
         
157
-        foreach($types as $type)
157
+        foreach ($types as $type)
158 158
         {
159 159
             $method = 'detectType_'.$type;
160 160
             
161
-            if($this->$method() === true) 
161
+            if ($this->$method() === true) 
162 162
             {
163 163
                 $this->isValid = true;
164 164
                 return true;
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
             'hostIsPresent'
177 177
         );
178 178
         
179
-        foreach($validations as $validation) 
179
+        foreach ($validations as $validation) 
180 180
         {
181 181
             $method = 'validate_'.$validation;
182 182
             
183
-            if($this->$method() !== true) {
183
+            if ($this->$method() !== true) {
184 184
                 return;
185 185
             }
186 186
         }
@@ -193,13 +193,13 @@  discard block
 block discarded – undo
193 193
         // every link needs a host. This case can happen for ex, if
194 194
         // the link starts with a typo with only one slash, like:
195 195
         // "http:/hostname"
196
-        if(isset($this->info['host'])) {
196
+        if (isset($this->info['host'])) {
197 197
             return true;
198 198
         }
199 199
         
200 200
         $this->setError(
201 201
             URLInfo::ERROR_MISSING_HOST,
202
-            t('Cannot determine the link\'s host name.') . ' ' .
202
+            t('Cannot determine the link\'s host name.').' '.
203 203
             t('This usually happens when there\'s a typo somewhere.')
204 204
         );
205 205
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
     
209 209
     protected function validate_schemeIsSet() : bool
210 210
     {
211
-        if(isset($this->info['scheme'])) {
211
+        if (isset($this->info['scheme'])) {
212 212
             return true;
213 213
         }
214 214
         
@@ -225,13 +225,13 @@  discard block
 block discarded – undo
225 225
     
226 226
     protected function validate_schemeIsKnown() : bool
227 227
     {
228
-        if(in_array($this->info['scheme'], $this->knownSchemes)) {
228
+        if (in_array($this->info['scheme'], $this->knownSchemes)) {
229 229
             return true;
230 230
         }
231 231
         
232 232
         $this->setError(
233 233
             URLInfo::ERROR_INVALID_SCHEME,
234
-            t('The scheme %1$s is not supported for links.', $this->info['scheme']) . ' ' .
234
+            t('The scheme %1$s is not supported for links.', $this->info['scheme']).' '.
235 235
             t('Valid schemes are: %1$s.', implode(', ', $this->knownSchemes))
236 236
         );
237 237
 
@@ -248,36 +248,36 @@  discard block
 block discarded – undo
248 248
         $this->info['params'] = array();
249 249
         $this->info['type'] = URLInfo::TYPE_URL;
250 250
 
251
-        if(isset($this->info['scheme']))
251
+        if (isset($this->info['scheme']))
252 252
         {
253 253
             $this->info['scheme'] = strtolower($this->info['scheme']);
254 254
         }
255 255
         else
256 256
         {
257 257
             $scheme = URLInfo_Schemes::detectScheme($this->url);
258
-            if(!empty($scheme)) {
259
-                $this->info['scheme'] = substr($scheme,0, strpos($scheme, ':'));
258
+            if (!empty($scheme)) {
259
+                $this->info['scheme'] = substr($scheme, 0, strpos($scheme, ':'));
260 260
             }
261 261
         }
262 262
 
263
-        if(isset($this->info['user'])) {
263
+        if (isset($this->info['user'])) {
264 264
             $this->info['user'] = urldecode($this->info['user']);
265 265
         }
266 266
 
267
-        if(isset($this->info['pass'])) {
267
+        if (isset($this->info['pass'])) {
268 268
             $this->info['pass'] = urldecode($this->info['pass']);
269 269
         }
270 270
         
271
-        if(isset($this->info['host'])) {
271
+        if (isset($this->info['host'])) {
272 272
             $this->info['host'] = strtolower($this->info['host']);
273 273
             $this->info['host'] = str_replace(' ', '', $this->info['host']);
274 274
         }
275 275
         
276
-        if(isset($this->info['path'])) {
276
+        if (isset($this->info['path'])) {
277 277
             $this->info['path'] = str_replace(' ', '', $this->info['path']);
278 278
         }
279 279
         
280
-        if(isset($this->info['query']) && !empty($this->info['query']))
280
+        if (isset($this->info['query']) && !empty($this->info['query']))
281 281
         {
282 282
             $this->info['params'] = ConvertHelper::parseQueryString($this->info['query']);
283 283
             ksort($this->info['params']);
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
     {
296 296
         $result = array();
297 297
         
298
-        foreach($subject as $key => $val)
298
+        foreach ($subject as $key => $val)
299 299
         {
300
-            if(is_array($val))
300
+            if (is_array($val))
301 301
             {
302 302
                 $val = $this->restoreUnicodeChars($val);
303 303
             }
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
     */
324 324
     protected function restoreUnicodeChar(string $string) : string
325 325
     {
326
-        if(strstr($string, '%'))
326
+        if (strstr($string, '%'))
327 327
         {
328 328
             return str_replace(array_keys($this->unicodeChars), array_values($this->unicodeChars), $string);
329 329
         }
@@ -333,12 +333,12 @@  discard block
 block discarded – undo
333 333
     
334 334
     protected function detectType_email() : bool
335 335
     {
336
-        if(isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') {
336
+        if (isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') {
337 337
             $this->info['type'] = URLInfo::TYPE_EMAIL;
338 338
             return true;
339 339
         }
340 340
         
341
-        if(isset($this->info['path']) && preg_match(RegexHelper::REGEX_EMAIL, $this->info['path']))
341
+        if (isset($this->info['path']) && preg_match(RegexHelper::REGEX_EMAIL, $this->info['path']))
342 342
         {
343 343
             $this->info['scheme'] = 'mailto';
344 344
             $this->info['type'] = URLInfo::TYPE_EMAIL;
@@ -350,13 +350,13 @@  discard block
 block discarded – undo
350 350
 
351 351
     protected function detectType_ipAddress() : bool
352 352
     {
353
-        if($this->isPathOnly() && preg_match(RegexHelper::REGEX_IPV4, $this->info['path'])) {
353
+        if ($this->isPathOnly() && preg_match(RegexHelper::REGEX_IPV4, $this->info['path'])) {
354 354
             $this->info['host'] = $this->info['path'];
355 355
             $this->info['scheme'] = 'https';
356 356
             unset($this->info['path']);
357 357
         }
358 358
 
359
-        if($this->isHostOnly() && preg_match(RegexHelper::REGEX_IPV4, $this->info['host'])) {
359
+        if ($this->isHostOnly() && preg_match(RegexHelper::REGEX_IPV4, $this->info['host'])) {
360 360
             $this->info['ip'] = $this->info['host'];
361 361
             return true;
362 362
         }
@@ -376,7 +376,7 @@  discard block
 block discarded – undo
376 376
 
377 377
     protected function detectType_fragmentLink() : bool
378 378
     {
379
-        if(isset($this->info['fragment']) && !isset($this->info['scheme'])) {
379
+        if (isset($this->info['fragment']) && !isset($this->info['scheme'])) {
380 380
             $this->info['type'] = URLInfo::TYPE_FRAGMENT;
381 381
             return true;
382 382
         }
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
     
387 387
     protected function detectType_phoneLink() : bool
388 388
     {
389
-        if(isset($this->info['scheme']) && $this->info['scheme'] == 'tel') {
389
+        if (isset($this->info['scheme']) && $this->info['scheme'] == 'tel') {
390 390
             $this->info['type'] = URLInfo::TYPE_PHONE;
391 391
             return true;
392 392
         }
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
     */
422 422
     public function getErrorMessage() : string
423 423
     {
424
-        if(isset($this->error)) {
424
+        if (isset($this->error)) {
425 425
             return $this->error['message'];
426 426
         }
427 427
         
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
     */
437 437
     public function getErrorCode() : int
438 438
     {
439
-        if(isset($this->error)) {
439
+        if (isset($this->error)) {
440 440
             return $this->error['code'];
441 441
         }
442 442
         
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -251,8 +251,7 @@  discard block
 block discarded – undo
251 251
         if(isset($this->info['scheme']))
252 252
         {
253 253
             $this->info['scheme'] = strtolower($this->info['scheme']);
254
-        }
255
-        else
254
+        } else
256 255
         {
257 256
             $scheme = URLInfo_Schemes::detectScheme($this->url);
258 257
             if(!empty($scheme)) {
@@ -300,8 +299,7 @@  discard block
 block discarded – undo
300 299
             if(is_array($val))
301 300
             {
302 301
                 $val = $this->restoreUnicodeChars($val);
303
-            }
304
-            else
302
+            } else
305 303
             {
306 304
                 $val = $this->restoreUnicodeChar($val);
307 305
             }
Please login to merge, or discard this patch.
src/URLInfo/Schemes.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
     {
73 73
         self::buildCache();
74 74
 
75
-        foreach(self::$cache as $scheme => $length) {
76
-            if(strtolower(substr($url, 0, $length)) === $scheme) {
75
+        foreach (self::$cache as $scheme => $length) {
76
+            if (strtolower(substr($url, 0, $length)) === $scheme) {
77 77
                 return $scheme;
78 78
             }
79 79
         }
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
      */
89 89
     private static function buildCache() : void
90 90
     {
91
-        if(!empty(self::$cache)) {
91
+        if (!empty(self::$cache)) {
92 92
             return;
93 93
         }
94 94
 
95
-        foreach(self::$schemes as $scheme) {
95
+        foreach (self::$schemes as $scheme) {
96 96
             self::$cache[$scheme] = strlen($scheme);
97 97
         }
98 98
     }
Please login to merge, or discard this patch.
src/RegexHelper.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -42,10 +42,10 @@  discard block
 block discarded – undo
42 42
     
43 43
     const REGEX_MD5 = '/^[a-f0-9]{32}$/i';
44 44
 
45
-   /**
46
-    * @var string
47
-    * @see https://en.wikipedia.org/wiki/Email_address#Local-part
48
-    */
45
+    /**
46
+     * @var string
47
+     * @see https://en.wikipedia.org/wiki/Email_address#Local-part
48
+     */
49 49
     const REGEX_EMAIL = '/[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i';
50 50
     
51 51
     const REGEX_PHONE = '/\A[+0-9][0-9 +\-()]+\z/m';
@@ -97,14 +97,14 @@  discard block
 block discarded – undo
97 97
      */
98 98
     const REGEX_IS_HTML = '%<{0,1}[a-z\/][\s\S]*>|<[a-z\/][\s\S]*>{0,1}%i';
99 99
     
100
-   /**
101
-    * Hexadecimal color codes. Allows the following formats:
102
-    * 
103
-    * FFFFFF
104
-    * FFF
105
-    * 
106
-    * @var string
107
-    */
100
+    /**
101
+     * Hexadecimal color codes. Allows the following formats:
102
+     * 
103
+     * FFFFFF
104
+     * FFF
105
+     * 
106
+     * @var string
107
+     */
108 108
     const REGEX_HEX_COLOR_CODE = '/\A(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\z/iU';
109 109
 
110 110
     /**
Please login to merge, or discard this patch.