Passed
Push — master ( d03553...18ea48 )
by Sebastian
02:14
created
src/Request.php 2 patches
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
      */
40 40
     protected static $instance;
41 41
     
42
-   /**
43
-    * @var string
44
-    */
42
+    /**
43
+     * @var string
44
+     */
45 45
     protected $baseURL = '';
46 46
     
47 47
     public function __construct()
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
         $this->init();
52 52
     }
53 53
     
54
-   /**
55
-    * Can be extended in a subclass, to avoid
56
-    * redefining the constructor.
57
-    */
54
+    /**
55
+     * Can be extended in a subclass, to avoid
56
+     * redefining the constructor.
57
+     */
58 58
     protected function init()
59 59
     {
60 60
         
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
         return $this->buildURL($params, $dispatcher);
125 125
     }
126 126
     
127
-   /**
128
-    * Retrieves the name of the current dispatcher script / page.
129
-    * This is made to be extended and implemented in a subclass.
130
-    * 
131
-    * @return string
132
-    */
127
+    /**
128
+     * Retrieves the name of the current dispatcher script / page.
129
+     * This is made to be extended and implemented in a subclass.
130
+     * 
131
+     * @return string
132
+     */
133 133
     public function getDispatcher() : string
134 134
     {
135 135
         return '';
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
         return $url;
199 199
     }
200 200
     
201
-   /**
202
-    * Retrieves the base URL of the application.
203
-    * @return string
204
-    */
201
+    /**
202
+     * Retrieves the base URL of the application.
203
+     * @return string
204
+     */
205 205
     public function getBaseURL() : string
206 206
     {
207 207
         return $this->baseURL;
@@ -231,13 +231,13 @@  discard block
 block discarded – undo
231 231
         return $this->knownParams[$name];
232 232
     }
233 233
     
234
-   /**
235
-    * Retrieves a previously registered parameter instance.
236
-    * 
237
-    * @param string $name
238
-    * @throws Request_Exception
239
-    * @return Request_Param
240
-    */
234
+    /**
235
+     * Retrieves a previously registered parameter instance.
236
+     * 
237
+     * @param string $name
238
+     * @throws Request_Exception
239
+     * @return Request_Param
240
+     */
241 241
     public function getRegisteredParam(string $name) : Request_Param
242 242
     {
243 243
         if(isset($this->knownParams[$name])) {
@@ -254,48 +254,48 @@  discard block
 block discarded – undo
254 254
         );
255 255
     }
256 256
     
257
-   /**
258
-    * Checks whether a parameter with the specified name 
259
-    * has been registered.
260
-    * 
261
-    * @param string $name
262
-    * @return bool
263
-    */
257
+    /**
258
+     * Checks whether a parameter with the specified name 
259
+     * has been registered.
260
+     * 
261
+     * @param string $name
262
+     * @return bool
263
+     */
264 264
     public function hasRegisteredParam(string $name) : bool
265 265
     {
266 266
         return isset($this->knownParams[$name]);
267 267
     }
268 268
     
269
-   /**
270
-    * Retrieves an indexed array with accept mime types
271
-    * that the client sent, in the order of preference
272
-    * the client specified.
273
-    *
274
-    * Example:
275
-    *
276
-    * array(
277
-    *     'text/html',
278
-    *     'application/xhtml+xml',
279
-    *     'image/webp'
280
-    *     ...
281
-    * )
282
-    * 
283
-    * @return array
284
-    * @see Request::parseAcceptHeaders()
285
-    */
269
+    /**
270
+     * Retrieves an indexed array with accept mime types
271
+     * that the client sent, in the order of preference
272
+     * the client specified.
273
+     *
274
+     * Example:
275
+     *
276
+     * array(
277
+     *     'text/html',
278
+     *     'application/xhtml+xml',
279
+     *     'image/webp'
280
+     *     ...
281
+     * )
282
+     * 
283
+     * @return array
284
+     * @see Request::parseAcceptHeaders()
285
+     */
286 286
     public static function getAcceptHeaders() : array
287 287
     {
288 288
         return self::parseAcceptHeaders()->getMimeStrings();
289 289
     }
290 290
     
291
-   /**
292
-    * Returns an instance of the accept headers parser,
293
-    * to access information on the browser's accepted
294
-    * mime types.
295
-    *  
296
-    * @return Request_AcceptHeaders
297
-    * @see Request::getAcceptHeaders()
298
-    */
291
+    /**
292
+     * Returns an instance of the accept headers parser,
293
+     * to access information on the browser's accepted
294
+     * mime types.
295
+     *  
296
+     * @return Request_AcceptHeaders
297
+     * @see Request::getAcceptHeaders()
298
+     */
299 299
     public static function parseAcceptHeaders() : Request_AcceptHeaders
300 300
     {
301 301
         static $accept;
@@ -343,14 +343,14 @@  discard block
 block discarded – undo
343 343
         return false;
344 344
     }
345 345
     
346
-   /**
347
-    * Removes a single parameter from the request.
348
-    * If the parameter has been registered, also
349
-    * removes the registration info.
350
-    * 
351
-    * @param string $name
352
-    * @return Request
353
-    */
346
+    /**
347
+     * Removes a single parameter from the request.
348
+     * If the parameter has been registered, also
349
+     * removes the registration info.
350
+     * 
351
+     * @param string $name
352
+     * @return Request
353
+     */
354 354
     public function removeParam(string $name) : Request
355 355
     {
356 356
         if(isset($_REQUEST[$name])) {
@@ -364,12 +364,12 @@  discard block
 block discarded – undo
364 364
         return $this;
365 365
     }
366 366
     
367
-   /**
368
-    * Removes several parameters from the request.
369
-    * 
370
-    * @param string[] $names
371
-    * @return Request
372
-    */
367
+    /**
368
+     * Removes several parameters from the request.
369
+     * 
370
+     * @param string[] $names
371
+     * @return Request
372
+     */
373 373
     public function removeParams(array $names) : Request
374 374
     {
375 375
         foreach($names as $name) {
@@ -434,18 +434,18 @@  discard block
 block discarded – undo
434 434
         return $val;
435 435
     }
436 436
     
437
-   /**
438
-    * Treats the request parameter as a JSON string, and
439
-    * if it exists and contains valid JSON, returns the
440
-    * decoded JSON value as an array (default).
441
-    *
442
-    * @param string $name
443
-    * @param bool $assoc
444
-    * @return array|object
445
-    * 
446
-    * @see Request::getJSONAssoc()
447
-    * @see Request::getJSONObject()
448
-    */
437
+    /**
438
+     * Treats the request parameter as a JSON string, and
439
+     * if it exists and contains valid JSON, returns the
440
+     * decoded JSON value as an array (default).
441
+     *
442
+     * @param string $name
443
+     * @param bool $assoc
444
+     * @return array|object
445
+     * 
446
+     * @see Request::getJSONAssoc()
447
+     * @see Request::getJSONObject()
448
+     */
449 449
     public function getJSON(string $name, bool $assoc=true)
450 450
     {
451 451
         $value = $this->getParam($name);
@@ -470,13 +470,13 @@  discard block
 block discarded – undo
470 470
         return new \stdClass();
471 471
     }
472 472
     
473
-   /**
474
-    * Like {@link Request::getJSON()}, but omitting the second
475
-    * parameter. Use this for more readable code.
476
-    * 
477
-    * @param string $name
478
-    * @return array
479
-    */
473
+    /**
474
+     * Like {@link Request::getJSON()}, but omitting the second
475
+     * parameter. Use this for more readable code.
476
+     * 
477
+     * @param string $name
478
+     * @return array
479
+     */
480 480
     public function getJSONAssoc(string $name) : array
481 481
     {
482 482
         $result = $this->getJSON($name);
@@ -487,13 +487,13 @@  discard block
 block discarded – undo
487 487
         return array();
488 488
     }
489 489
     
490
-   /**
491
-    * Like {@link Request::getJSON()}, but omitting the second
492
-    * parameter. Use this for more readable code.
493
-    *
494
-    * @param string $name
495
-    * @return object
496
-    */
490
+    /**
491
+     * Like {@link Request::getJSON()}, but omitting the second
492
+     * parameter. Use this for more readable code.
493
+     *
494
+     * @param string $name
495
+     * @return object
496
+     */
497 497
     public function getJSONObject(string $name) : object
498 498
     {
499 499
         $result = $this->getJSON($name, false);
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
         return new \stdClass();
505 505
     }
506 506
     
507
-   /**
508
-    * Sends a JSON response with the correct headers.
509
-    *
510
-    * @param array|string $data
511
-    * @param bool $exit Whether to exit the script afterwards.
512
-    */
507
+    /**
508
+     * Sends a JSON response with the correct headers.
509
+     *
510
+     * @param array|string $data
511
+     * @param bool $exit Whether to exit the script afterwards.
512
+     */
513 513
     public static function sendJSON($data, bool $exit=true)
514 514
     {
515 515
         $payload = $data;
@@ -529,12 +529,12 @@  discard block
 block discarded – undo
529 529
         }
530 530
     }
531 531
     
532
-   /**
533
-    * Sends HTML to the browser with the correct headers.
534
-    * 
535
-    * @param string $html
536
-    * @param bool $exit Whether to exit the script afterwards.
537
-    */
532
+    /**
533
+     * Sends HTML to the browser with the correct headers.
534
+     * 
535
+     * @param string $html
536
+     * @param bool $exit Whether to exit the script afterwards.
537
+     */
538 538
     public static function sendHTML(string $html, bool $exit=true)
539 539
     {
540 540
         header('Cache-Control: no-cache, must-revalidate');
@@ -549,16 +549,16 @@  discard block
 block discarded – undo
549 549
         }
550 550
     }
551 551
     
552
-   /**
553
-    * Creates a new instance of the URL comparer, which can check 
554
-    * whether the specified URLs match, regardless of the order in 
555
-    * which the query parameters are, if any.
556
-    * 
557
-    * @param string $sourceURL
558
-    * @param string $targetURL
559
-    * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present)
560
-    * @return Request_URLComparer
561
-    */
552
+    /**
553
+     * Creates a new instance of the URL comparer, which can check 
554
+     * whether the specified URLs match, regardless of the order in 
555
+     * which the query parameters are, if any.
556
+     * 
557
+     * @param string $sourceURL
558
+     * @param string $targetURL
559
+     * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present)
560
+     * @return Request_URLComparer
561
+     */
562 562
     public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer
563 563
     {
564 564
         $comparer = new Request_URLComparer($this, $sourceURL, $targetURL);
@@ -567,10 +567,10 @@  discard block
 block discarded – undo
567 567
         return $comparer;
568 568
     }
569 569
     
570
-   /**
571
-    * Retrieves the full URL that was used to access the current page.
572
-    * @return string
573
-    */
570
+    /**
571
+     * Retrieves the full URL that was used to access the current page.
572
+     * @return string
573
+     */
574 574
     public function getCurrentURL() : string
575 575
     {
576 576
         return $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -90,11 +90,11 @@  discard block
 block discarded – undo
90 90
     public function getParam($name, $default = null)
91 91
     {
92 92
         $value = $default;
93
-        if(isset($_REQUEST[$name])) {
93
+        if (isset($_REQUEST[$name])) {
94 94
             $value = $_REQUEST[$name];
95 95
         }
96 96
         
97
-        if(isset($this->knownParams[$name])) {
97
+        if (isset($this->knownParams[$name])) {
98 98
             $value = $this->knownParams[$name]->validate($value);
99 99
         }
100 100
         
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
         
144 144
         $exclude = array_merge($exclude, $this->getExcludeParams());
145 145
         
146
-        foreach($exclude as $name) 
146
+        foreach ($exclude as $name) 
147 147
         {
148
-            if(isset($vars[$name])) 
148
+            if (isset($vars[$name])) 
149 149
             {
150 150
                 unset($vars[$name]);
151 151
             }
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
         // remove the HTML_QuickForm2 form variable if present, to 
157 157
         // avoid redirect loops when using the refresh URL in
158 158
         // a page in which a form has been submitted.
159
-        foreach($names as $name) 
159
+        foreach ($names as $name) 
160 160
         {
161
-            if(strstr($name, '_qf__')) 
161
+            if (strstr($name, '_qf__')) 
162 162
             {
163 163
                 unset($vars[$name]);
164 164
                 break;
@@ -186,13 +186,13 @@  discard block
 block discarded – undo
186 186
      * @param string $dispatcher Relative path to script to use for the URL. Append trailing slash if needed.
187 187
      * @return string
188 188
      */
189
-    public function buildURL($params = array(), string $dispatcher='')
189
+    public function buildURL($params = array(), string $dispatcher = '')
190 190
     {
191
-        $url = rtrim($this->getBaseURL(), '/') . '/' . $dispatcher;
191
+        $url = rtrim($this->getBaseURL(), '/').'/'.$dispatcher;
192 192
         
193 193
         // append any leftover parameters to the end of the URL
194 194
         if (!empty($params)) {
195
-            $url .= '?' . http_build_query($params, null, '&');
195
+            $url .= '?'.http_build_query($params, null, '&');
196 196
         }
197 197
         
198 198
         return $url;
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      */
224 224
     public function registerParam($name)
225 225
     {
226
-        if(!isset($this->knownParams[$name])) {
226
+        if (!isset($this->knownParams[$name])) {
227 227
             $param = new Request_Param($this, $name);
228 228
             $this->knownParams[$name] = $param;
229 229
         }
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
     */
241 241
     public function getRegisteredParam(string $name) : Request_Param
242 242
     {
243
-        if(isset($this->knownParams[$name])) {
243
+        if (isset($this->knownParams[$name])) {
244 244
             return $this->knownParams[$name];
245 245
         }
246 246
         
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
     {
301 301
         static $accept;
302 302
         
303
-        if(!isset($accept)) {
303
+        if (!isset($accept)) {
304 304
             $accept = new Request_AcceptHeaders();
305 305
         }
306 306
         
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
     {
320 320
         $_REQUEST[$name] = $value;
321 321
         
322
-        if(isset($this->knownParams[$name])) {
322
+        if (isset($this->knownParams[$name])) {
323 323
             unset($this->knownParams[$name]);
324 324
         }
325 325
         
@@ -353,11 +353,11 @@  discard block
 block discarded – undo
353 353
     */
354 354
     public function removeParam(string $name) : Request
355 355
     {
356
-        if(isset($_REQUEST[$name])) {
356
+        if (isset($_REQUEST[$name])) {
357 357
             unset($_REQUEST[$name]);
358 358
         }
359 359
         
360
-        if(isset($this->knownParams[$name])) {
360
+        if (isset($this->knownParams[$name])) {
361 361
             unset($this->knownParams[$name]);
362 362
         }
363 363
         
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
     */
373 373
     public function removeParams(array $names) : Request
374 374
     {
375
-        foreach($names as $name) {
375
+        foreach ($names as $name) {
376 376
             $this->removeParam($name);
377 377
         }
378 378
         
@@ -388,10 +388,10 @@  discard block
 block discarded – undo
388 388
      * @param string $name
389 389
      * @return bool
390 390
      */
391
-    public function getBool($name, $default=false)
391
+    public function getBool($name, $default = false)
392 392
     {
393 393
         $value = $this->getParam($name, $default);
394
-        if(ConvertHelper::isBoolean($value)) {
394
+        if (ConvertHelper::isBoolean($value)) {
395 395
             return ConvertHelper::string2bool($value);
396 396
         }
397 397
         
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
     
401 401
     public function validate()
402 402
     {
403
-        foreach($this->knownParams as $param) 
403
+        foreach ($this->knownParams as $param) 
404 404
         {
405 405
             $name = $param->getName();
406 406
             
407
-            if($param->isRequired() && !$this->hasParam($name)) 
407
+            if ($param->isRequired() && !$this->hasParam($name)) 
408 408
             {
409 409
                 throw new Request_Exception(
410 410
                     'Missing request parameter '.$name,
@@ -426,10 +426,10 @@  discard block
 block discarded – undo
426 426
      * @param mixed $default
427 427
      * @return string
428 428
      */
429
-    public function getFilteredParam($name, $default=null)
429
+    public function getFilteredParam($name, $default = null)
430 430
     {
431 431
         $val = $this->getParam($name, $default);
432
-        if(is_string($val)) {
432
+        if (is_string($val)) {
433 433
             $val = htmlspecialchars(trim(strip_tags($val)), ENT_QUOTES, 'UTF-8');
434 434
         }
435 435
         
@@ -448,24 +448,24 @@  discard block
 block discarded – undo
448 448
     * @see Request::getJSONAssoc()
449 449
     * @see Request::getJSONObject()
450 450
     */
451
-    public function getJSON(string $name, bool $assoc=true)
451
+    public function getJSON(string $name, bool $assoc = true)
452 452
     {
453 453
         $value = $this->getParam($name);
454 454
         
455
-        if(!empty($value) && is_string($value)) 
455
+        if (!empty($value) && is_string($value)) 
456 456
         {
457 457
             $data = json_decode($value, $assoc);
458 458
             
459
-            if($assoc && is_array($data)) {
459
+            if ($assoc && is_array($data)) {
460 460
                 return $data;
461 461
             }
462 462
             
463
-            if(is_object($data)) {
463
+            if (is_object($data)) {
464 464
                 return $data;
465 465
             }
466 466
         }
467 467
         
468
-        if($assoc) {
468
+        if ($assoc) {
469 469
             return array();
470 470
         }
471 471
         
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
     public function getJSONAssoc(string $name) : array
483 483
     {
484 484
         $result = $this->getJSON($name);
485
-        if(is_array($result)) {
485
+        if (is_array($result)) {
486 486
             return $result;
487 487
         }
488 488
         
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
     public function getJSONObject(string $name) : object
500 500
     {
501 501
         $result = $this->getJSON($name, false);
502
-        if(is_object($result)) {
502
+        if (is_object($result)) {
503 503
             return $result;
504 504
         }
505 505
         
@@ -512,10 +512,10 @@  discard block
 block discarded – undo
512 512
     * @param array|string $data
513 513
     * @param bool $exit Whether to exit the script afterwards.
514 514
     */
515
-    public static function sendJSON($data, bool $exit=true)
515
+    public static function sendJSON($data, bool $exit = true)
516 516
     {
517 517
         $payload = $data;
518
-        if(!is_string($payload)) {
518
+        if (!is_string($payload)) {
519 519
             $payload = json_encode($payload);
520 520
         }
521 521
         
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
         
526 526
         echo $payload;
527 527
         
528
-        if($exit) 
528
+        if ($exit) 
529 529
         {
530 530
             exit;
531 531
         }
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
     * @param string $html
538 538
     * @param bool $exit Whether to exit the script afterwards.
539 539
     */
540
-    public static function sendHTML(string $html, bool $exit=true)
540
+    public static function sendHTML(string $html, bool $exit = true)
541 541
     {
542 542
         header('Cache-Control: no-cache, must-revalidate');
543 543
         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
@@ -545,7 +545,7 @@  discard block
 block discarded – undo
545 545
         
546 546
         echo $html;
547 547
         
548
-        if($exit)
548
+        if ($exit)
549 549
         {
550 550
             exit;
551 551
         }
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
     * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present)
562 562
     * @return Request_URLComparer
563 563
     */
564
-    public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer
564
+    public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams = array()) : Request_URLComparer
565 565
     {
566 566
         $comparer = new Request_URLComparer($this, $sourceURL, $targetURL);
567 567
         $comparer->addLimitParams($limitParams);
Please login to merge, or discard this patch.
src/Request/AcceptHeaders.php 3 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -28,20 +28,20 @@  discard block
 block discarded – undo
28 28
         $this->parse();
29 29
     }
30 30
     
31
-   /**
32
-    * Retrieves an indexed array with accept mime types
33
-    * that the client sent, in the order of preference
34
-    * the client specified.
35
-    *
36
-    * Example:
37
-    *
38
-    * array(
39
-    *     'text/html',
40
-    *     'application/xhtml+xml',
41
-    *     'image/webp'
42
-    *     ...
43
-    * )
44
-    */
31
+    /**
32
+     * Retrieves an indexed array with accept mime types
33
+     * that the client sent, in the order of preference
34
+     * the client specified.
35
+     *
36
+     * Example:
37
+     *
38
+     * array(
39
+     *     'text/html',
40
+     *     'application/xhtml+xml',
41
+     *     'image/webp'
42
+     *     ...
43
+     * )
44
+     */
45 45
     public function getMimeStrings() : array
46 46
     {
47 47
         $result = array();
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
         return $result;
55 55
     }
56 56
     
57
-   /**
58
-    * Checks that an accept header string exists, and tries to parse it.
59
-    */
57
+    /**
58
+     * Checks that an accept header string exists, and tries to parse it.
59
+     */
60 60
     protected function parse() : void
61 61
     {
62 62
         // we may be in a CLI environment where the headers
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
         $this->headers = $this->parseHeader($_SERVER['HTTP_ACCEPT']);
69 69
     }
70 70
     
71
-   /**
72
-    * Splits the accept header string and parses the mime types.
73
-    *  
74
-    * @param string $acceptHeader 
75
-    */
71
+    /**
72
+     * Splits the accept header string and parses the mime types.
73
+     *  
74
+     * @param string $acceptHeader 
75
+     */
76 76
     protected function parseHeader(string $acceptHeader) : array
77 77
     {
78 78
         $tokens = preg_split('/\s*,\s*/', $acceptHeader);
@@ -89,13 +89,13 @@  discard block
 block discarded – undo
89 89
         return $accept;
90 90
     }
91 91
     
92
-   /**
93
-    * Parses a single mime type entry.
94
-    * 
95
-    * @param int $i The position in the accept string
96
-    * @param string $mime The mime type
97
-    * @return array
98
-    */
92
+    /**
93
+     * Parses a single mime type entry.
94
+     * 
95
+     * @param int $i The position in the accept string
96
+     * @param string $mime The mime type
97
+     * @return array
98
+     */
99 99
     protected function parseEntry(int $i, string $mime) : array
100 100
     {
101 101
         $entry = array(
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
         return $entry;
126 126
     }
127 127
     
128
-   /**
129
-    * Sorts the mime types collection, first by quality
130
-    * and then by position in the list.
131
-    * 
132
-    * @param array $a
133
-    * @param array $b
134
-    * @return number
135
-    */
128
+    /**
129
+     * Sorts the mime types collection, first by quality
130
+     * and then by position in the list.
131
+     * 
132
+     * @param array $a
133
+     * @param array $b
134
+     * @return number
135
+     */
136 136
     protected function sortMimeTypes(array $a, array $b)
137 137
     {
138 138
         /* first tier: highest q factor wins */
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
     {
47 47
         $result = array();
48 48
         
49
-        foreach($this->headers as $header)
49
+        foreach ($this->headers as $header)
50 50
         {
51 51
             $result[] = $header['type'];
52 52
         }
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     {
62 62
         // we may be in a CLI environment where the headers
63 63
         // are not populated.
64
-        if(!isset($_SERVER['HTTP_ACCEPT'])) {
64
+        if (!isset($_SERVER['HTTP_ACCEPT'])) {
65 65
             return;
66 66
         }
67 67
         
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         
80 80
         $accept = array();
81 81
         
82
-        foreach($tokens as $i => $term)
82
+        foreach ($tokens as $i => $term)
83 83
         {
84 84
             $accept[] = $this->parseEntry($i, $term);
85 85
         }
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
             'type' => null
106 106
         );
107 107
         
108
-        if(strstr($mime, ';'))
108
+        if (strstr($mime, ';'))
109 109
         {
110 110
             $parts = explode(';', $mime);
111 111
             $mime = array_shift($parts);
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
             // like an URL query string if separated by ampersands;
115 115
             $entry['params'] = ConvertHelper::parseQueryString(implode('&', $parts));
116 116
                 
117
-            if(isset($entry['params']['q'])) 
117
+            if (isset($entry['params']['q'])) 
118 118
             {
119 119
                 $entry['quality'] = (double)$entry['params']['q'];
120 120
             } 
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -141,14 +141,12 @@
 block discarded – undo
141 141
         if ($diff > 0) 
142 142
         {
143 143
             $diff = 1;
144
-        } 
145
-        else 
144
+        } else 
146 145
         {
147 146
             if ($diff < 0) 
148 147
             {
149 148
                 $diff = -1;
150
-            } 
151
-            else 
149
+            } else 
152 150
             {
153 151
                 /* tie-breaker: first listed item wins */
154 152
                 $diff = $a['pos'] - $b['pos'];
Please login to merge, or discard this patch.
src/FileHelper.php 3 patches
Indentation   +410 added lines, -410 removed lines patch added patch discarded remove patch
@@ -76,32 +76,32 @@  discard block
 block discarded – undo
76 76
     
77 77
     const ERROR_CANNOT_OPEN_FILE_TO_DETECT_BOM = 340032;
78 78
     
79
-   /**
80
-    * Opens a serialized file and returns the unserialized data.
81
-    * 
82
-    * @param string $file
83
-    * @throws FileHelper_Exception
84
-    * @return array
85
-    * @deprecated Use parseSerializedFile() instead.
86
-    * @see FileHelper::parseSerializedFile()
87
-    */
79
+    /**
80
+     * Opens a serialized file and returns the unserialized data.
81
+     * 
82
+     * @param string $file
83
+     * @throws FileHelper_Exception
84
+     * @return array
85
+     * @deprecated Use parseSerializedFile() instead.
86
+     * @see FileHelper::parseSerializedFile()
87
+     */
88 88
     public static function openUnserialized(string $file) : array
89 89
     {
90 90
         return self::parseSerializedFile($file);
91 91
     }
92 92
 
93
-   /**
94
-    * Opens a serialized file and returns the unserialized data.
95
-    *
96
-    * @param string $file
97
-    * @throws FileHelper_Exception
98
-    * @return array
99
-    * @see FileHelper::parseSerializedFile()
100
-    * 
101
-    * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
102
-    * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ
103
-    * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED
104
-    */
93
+    /**
94
+     * Opens a serialized file and returns the unserialized data.
95
+     *
96
+     * @param string $file
97
+     * @throws FileHelper_Exception
98
+     * @return array
99
+     * @see FileHelper::parseSerializedFile()
100
+     * 
101
+     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
102
+     * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ
103
+     * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED
104
+     */
105 105
     public static function parseSerializedFile(string $file)
106 106
     {
107 107
         self::requireFileExists($file);
@@ -170,13 +170,13 @@  discard block
 block discarded – undo
170 170
         return rmdir($rootFolder);
171 171
     }
172 172
     
173
-   /**
174
-    * Create a folder, if it does not exist yet.
175
-    *  
176
-    * @param string $path
177
-    * @throws FileHelper_Exception
178
-    * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER
179
-    */
173
+    /**
174
+     * Create a folder, if it does not exist yet.
175
+     *  
176
+     * @param string $path
177
+     * @throws FileHelper_Exception
178
+     * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER
179
+     */
180 180
     public static function createFolder($path)
181 181
     {
182 182
         if(is_dir($path) || mkdir($path, 0777, true)) {
@@ -223,22 +223,22 @@  discard block
 block discarded – undo
223 223
         }
224 224
     }
225 225
     
226
-   /**
227
-    * Copies a file to the target location. Includes checks
228
-    * for most error sources, like the source file not being
229
-    * readable. Automatically creates the target folder if it
230
-    * does not exist yet.
231
-    * 
232
-    * @param string $sourcePath
233
-    * @param string $targetPath
234
-    * @throws FileHelper_Exception
235
-    * 
236
-    * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER
237
-    * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND
238
-    * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE
239
-    * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE
240
-    * @see FileHelper::ERROR_CANNOT_COPY_FILE
241
-    */
226
+    /**
227
+     * Copies a file to the target location. Includes checks
228
+     * for most error sources, like the source file not being
229
+     * readable. Automatically creates the target folder if it
230
+     * does not exist yet.
231
+     * 
232
+     * @param string $sourcePath
233
+     * @param string $targetPath
234
+     * @throws FileHelper_Exception
235
+     * 
236
+     * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER
237
+     * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND
238
+     * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE
239
+     * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE
240
+     * @see FileHelper::ERROR_CANNOT_COPY_FILE
241
+     */
242 242
     public static function copyFile($sourcePath, $targetPath)
243 243
     {
244 244
         self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND);
@@ -289,15 +289,15 @@  discard block
 block discarded – undo
289 289
         );
290 290
     }
291 291
     
292
-   /**
293
-    * Deletes the target file. Ignored if it cannot be found,
294
-    * and throws an exception if it fails.
295
-    * 
296
-    * @param string $filePath
297
-    * @throws FileHelper_Exception
298
-    * 
299
-    * @see FileHelper::ERROR_CANNOT_DELETE_FILE
300
-    */
292
+    /**
293
+     * Deletes the target file. Ignored if it cannot be found,
294
+     * and throws an exception if it fails.
295
+     * 
296
+     * @param string $filePath
297
+     * @throws FileHelper_Exception
298
+     * 
299
+     * @see FileHelper::ERROR_CANNOT_DELETE_FILE
300
+     */
301 301
     public static function deleteFile(string $filePath) : void
302 302
     {
303 303
         if(!file_exists($filePath)) {
@@ -319,15 +319,15 @@  discard block
 block discarded – undo
319 319
     }
320 320
 
321 321
     /**
322
-    * Creates a new CSV parser instance and returns it.
323
-    * 
324
-    * @param string $delimiter
325
-    * @param string $enclosure
326
-    * @param string $escape
327
-    * @param bool $heading
328
-    * @return \parseCSV
329
-    * @todo Move this to the CSV helper.
330
-    */
322
+     * Creates a new CSV parser instance and returns it.
323
+     * 
324
+     * @param string $delimiter
325
+     * @param string $enclosure
326
+     * @param string $escape
327
+     * @param bool $heading
328
+     * @return \parseCSV
329
+     * @todo Move this to the CSV helper.
330
+     */
331 331
     public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : \parseCSV
332 332
     {
333 333
         if($delimiter==='') { $delimiter = ';'; }
@@ -342,23 +342,23 @@  discard block
 block discarded – undo
342 342
         return $parser;
343 343
     }
344 344
 
345
-   /**
346
-    * Parses all lines in the specified string and returns an
347
-    * indexed array with all csv values in each line.
348
-    *
349
-    * @param string $csv
350
-    * @param string $delimiter
351
-    * @param string $enclosure
352
-    * @param string $escape
353
-    * @param bool $heading
354
-    * @return array
355
-    * @throws FileHelper_Exception
356
-    * 
357
-    * @todo Move this to the CSVHelper.
358
-    *
359
-    * @see parseCSVFile()
360
-    * @see FileHelper::ERROR_PARSING_CSV
361
-    */
345
+    /**
346
+     * Parses all lines in the specified string and returns an
347
+     * indexed array with all csv values in each line.
348
+     *
349
+     * @param string $csv
350
+     * @param string $delimiter
351
+     * @param string $enclosure
352
+     * @param string $escape
353
+     * @param bool $heading
354
+     * @return array
355
+     * @throws FileHelper_Exception
356
+     * 
357
+     * @todo Move this to the CSVHelper.
358
+     *
359
+     * @see parseCSVFile()
360
+     * @see FileHelper::ERROR_PARSING_CSV
361
+     */
362 362
     public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array
363 363
     {
364 364
         $parser = self::createCSVParser($delimiter, $enclosure, $escape, $heading);
@@ -537,31 +537,31 @@  discard block
 block discarded – undo
537 537
         );
538 538
     }
539 539
     
540
-   /**
541
-    * Verifies whether the target file is a PHP file. The path
542
-    * to the file can be a path to a file as a string, or a 
543
-    * DirectoryIterator object instance.
544
-    * 
545
-    * @param string|\DirectoryIterator $pathOrDirIterator
546
-    * @return boolean
547
-    */
540
+    /**
541
+     * Verifies whether the target file is a PHP file. The path
542
+     * to the file can be a path to a file as a string, or a 
543
+     * DirectoryIterator object instance.
544
+     * 
545
+     * @param string|\DirectoryIterator $pathOrDirIterator
546
+     * @return boolean
547
+     */
548 548
     public static function isPHPFile($pathOrDirIterator)
549 549
     {
550
-    	if(self::getExtension($pathOrDirIterator) == 'php') {
551
-    		return true;
552
-    	}
550
+        if(self::getExtension($pathOrDirIterator) == 'php') {
551
+            return true;
552
+        }
553 553
     	
554
-    	return false;
554
+        return false;
555 555
     }
556 556
     
557
-   /**
558
-    * Retrieves the extension of the specified file. Can be a path
559
-    * to a file as a string, or a DirectoryIterator object instance.
560
-    * 
561
-    * @param string|\DirectoryIterator $pathOrDirIterator
562
-    * @param bool $lowercase
563
-    * @return string
564
-    */
557
+    /**
558
+     * Retrieves the extension of the specified file. Can be a path
559
+     * to a file as a string, or a DirectoryIterator object instance.
560
+     * 
561
+     * @param string|\DirectoryIterator $pathOrDirIterator
562
+     * @param bool $lowercase
563
+     * @return string
564
+     */
565 565
     public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string
566 566
     {
567 567
         if($pathOrDirIterator instanceof \DirectoryIterator) {
@@ -572,51 +572,51 @@  discard block
 block discarded – undo
572 572
          
573 573
         $ext = pathinfo($filename, PATHINFO_EXTENSION);
574 574
         if($lowercase) {
575
-        	$ext = mb_strtolower($ext);
575
+            $ext = mb_strtolower($ext);
576 576
         }
577 577
         
578 578
         return $ext;
579 579
     }
580 580
     
581
-   /**
582
-    * Retrieves the file name from a path, with or without extension.
583
-    * The path to the file can be a string, or a DirectoryIterator object
584
-    * instance.
585
-    * 
586
-    * In case of folders, behaves like the pathinfo function: returns
587
-    * the name of the folder.
588
-    * 
589
-    * @param string|\DirectoryIterator $pathOrDirIterator
590
-    * @param bool $extension
591
-    * @return string
592
-    */
581
+    /**
582
+     * Retrieves the file name from a path, with or without extension.
583
+     * The path to the file can be a string, or a DirectoryIterator object
584
+     * instance.
585
+     * 
586
+     * In case of folders, behaves like the pathinfo function: returns
587
+     * the name of the folder.
588
+     * 
589
+     * @param string|\DirectoryIterator $pathOrDirIterator
590
+     * @param bool $extension
591
+     * @return string
592
+     */
593 593
     public static function getFilename($pathOrDirIterator, $extension = true)
594 594
     {
595 595
         $path = $pathOrDirIterator;
596
-    	if($pathOrDirIterator instanceof \DirectoryIterator) {
597
-    		$path = $pathOrDirIterator->getFilename();
598
-    	}
596
+        if($pathOrDirIterator instanceof \DirectoryIterator) {
597
+            $path = $pathOrDirIterator->getFilename();
598
+        }
599 599
     	
600
-    	$path = self::normalizePath($path);
600
+        $path = self::normalizePath($path);
601 601
     	
602
-    	if(!$extension) {
603
-    	    return pathinfo($path, PATHINFO_FILENAME);
604
-    	}
602
+        if(!$extension) {
603
+            return pathinfo($path, PATHINFO_FILENAME);
604
+        }
605 605
     	
606
-    	return pathinfo($path, PATHINFO_BASENAME); 
606
+        return pathinfo($path, PATHINFO_BASENAME); 
607 607
     }
608 608
    
609
-   /**
610
-    * Tries to read the contents of the target file and
611
-    * treat it as JSON to return the decoded JSON data.
612
-    * 
613
-    * @param string $file
614
-    * @throws FileHelper_Exception
615
-    * @return array
616
-    * 
617
-    * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE
618
-    * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE
619
-    */ 
609
+    /**
610
+     * Tries to read the contents of the target file and
611
+     * treat it as JSON to return the decoded JSON data.
612
+     * 
613
+     * @param string $file
614
+     * @throws FileHelper_Exception
615
+     * @return array
616
+     * 
617
+     * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE
618
+     * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE
619
+     */ 
620 620
     public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null)
621 621
     {
622 622
         self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE);
@@ -652,16 +652,16 @@  discard block
 block discarded – undo
652 652
         return $json;
653 653
     }
654 654
     
655
-   /**
656
-    * Corrects common formatting mistakes when users enter
657
-    * file names, like too many spaces, dots and the like.
658
-    * 
659
-    * NOTE: if the file name contains a path, the path is
660
-    * stripped, leaving only the file name.
661
-    * 
662
-    * @param string $name
663
-    * @return string
664
-    */
655
+    /**
656
+     * Corrects common formatting mistakes when users enter
657
+     * file names, like too many spaces, dots and the like.
658
+     * 
659
+     * NOTE: if the file name contains a path, the path is
660
+     * stripped, leaving only the file name.
661
+     * 
662
+     * @param string $name
663
+     * @return string
664
+     */
665 665
     public static function fixFileName(string $name) : string
666 666
     {
667 667
         $name = trim($name);
@@ -691,68 +691,68 @@  discard block
 block discarded – undo
691 691
         return $name;
692 692
     }
693 693
     
694
-   /**
695
-    * Creates an instance of the file finder, which is an easier
696
-    * alternative to the other manual findFile methods, since all
697
-    * options can be set by chaining.
698
-    * 
699
-    * @param string $path
700
-    * @return FileHelper_FileFinder
701
-    */
694
+    /**
695
+     * Creates an instance of the file finder, which is an easier
696
+     * alternative to the other manual findFile methods, since all
697
+     * options can be set by chaining.
698
+     * 
699
+     * @param string $path
700
+     * @return FileHelper_FileFinder
701
+     */
702 702
     public static function createFileFinder(string $path) : FileHelper_FileFinder
703 703
     {
704 704
         return new FileHelper_FileFinder($path);
705 705
     }
706 706
     
707
-   /**
708
-    * Searches for all HTML files in the target folder.
709
-    * 
710
-    * NOTE: This method only exists for backwards compatibility.
711
-    * Use the `createFileFinder()` method instead, which offers
712
-    * an object oriented interface that is much easier to use.
713
-    * 
714
-    * @param string $targetFolder
715
-    * @param array $options
716
-    * @return array An indexed array with files.
717
-    * @see FileHelper::createFileFinder()
718
-    */
707
+    /**
708
+     * Searches for all HTML files in the target folder.
709
+     * 
710
+     * NOTE: This method only exists for backwards compatibility.
711
+     * Use the `createFileFinder()` method instead, which offers
712
+     * an object oriented interface that is much easier to use.
713
+     * 
714
+     * @param string $targetFolder
715
+     * @param array $options
716
+     * @return array An indexed array with files.
717
+     * @see FileHelper::createFileFinder()
718
+     */
719 719
     public static function findHTMLFiles(string $targetFolder, array $options=array()) : array
720 720
     {
721 721
         return self::findFiles($targetFolder, array('html'), $options);
722 722
     }
723 723
 
724
-   /**
725
-    * Searches for all PHP files in the target folder.
726
-    * 
727
-    * NOTE: This method only exists for backwards compatibility.
728
-    * Use the `createFileFinder()` method instead, which offers
729
-    * an object oriented interface that is much easier to use.
730
-    * 
731
-    * @param string $targetFolder
732
-    * @param array $options
733
-    * @return array An indexed array of PHP files.
734
-    * @see FileHelper::createFileFinder()
735
-    */
724
+    /**
725
+     * Searches for all PHP files in the target folder.
726
+     * 
727
+     * NOTE: This method only exists for backwards compatibility.
728
+     * Use the `createFileFinder()` method instead, which offers
729
+     * an object oriented interface that is much easier to use.
730
+     * 
731
+     * @param string $targetFolder
732
+     * @param array $options
733
+     * @return array An indexed array of PHP files.
734
+     * @see FileHelper::createFileFinder()
735
+     */
736 736
     public static function findPHPFiles(string $targetFolder, array $options=array()) : array
737 737
     {
738 738
         return self::findFiles($targetFolder, array('php'), $options);
739 739
     }
740 740
     
741
-   /**
742
-    * Finds files according to the specified options.
743
-    * 
744
-    * NOTE: This method only exists for backwards compatibility.
745
-    * Use the `createFileFinder()` method instead, which offers
746
-    * an object oriented interface that is much easier to use.
747
-    *  
748
-    * @param string $targetFolder
749
-    * @param array $extensions
750
-    * @param array $options
751
-    * @param array $files
752
-    * @throws FileHelper_Exception
753
-    * @return array
754
-    * @see FileHelper::createFileFinder()
755
-    */
741
+    /**
742
+     * Finds files according to the specified options.
743
+     * 
744
+     * NOTE: This method only exists for backwards compatibility.
745
+     * Use the `createFileFinder()` method instead, which offers
746
+     * an object oriented interface that is much easier to use.
747
+     *  
748
+     * @param string $targetFolder
749
+     * @param array $extensions
750
+     * @param array $options
751
+     * @param array $files
752
+     * @throws FileHelper_Exception
753
+     * @return array
754
+     * @see FileHelper::createFileFinder()
755
+     */
756 756
     public static function findFiles(string $targetFolder, array $extensions=array(), array $options=array(), array $files=array()) : array
757 757
     {
758 758
         $finder = self::createFileFinder($targetFolder);
@@ -776,13 +776,13 @@  discard block
 block discarded – undo
776 776
         return $files;
777 777
     }
778 778
 
779
-   /**
780
-    * Removes the extension from the specified path or file name,
781
-    * if any, and returns the name without the extension.
782
-    * 
783
-    * @param string $filename
784
-    * @return sTring
785
-    */
779
+    /**
780
+     * Removes the extension from the specified path or file name,
781
+     * if any, and returns the name without the extension.
782
+     * 
783
+     * @param string $filename
784
+     * @return sTring
785
+     */
786 786
     public static function removeExtension(string $filename) : string
787 787
     {
788 788
         // normalize paths to allow windows style slashes even on nix servers
@@ -791,22 +791,22 @@  discard block
 block discarded – undo
791 791
         return pathinfo($filename, PATHINFO_FILENAME);
792 792
     }
793 793
     
794
-   /**
795
-    * Detects the UTF BOM in the target file, if any. Returns
796
-    * the encoding matching the BOM, which can be any of the
797
-    * following:
798
-    * 
799
-    * <ul>
800
-    * <li>UTF32-BE</li>
801
-    * <li>UTF32-LE</li>
802
-    * <li>UTF16-BE</li>
803
-    * <li>UTF16-LE</li>
804
-    * <li>UTF8</li>
805
-    * </ul>
806
-    * 
807
-    * @param string $filename
808
-    * @return string|NULL
809
-    */
794
+    /**
795
+     * Detects the UTF BOM in the target file, if any. Returns
796
+     * the encoding matching the BOM, which can be any of the
797
+     * following:
798
+     * 
799
+     * <ul>
800
+     * <li>UTF32-BE</li>
801
+     * <li>UTF32-LE</li>
802
+     * <li>UTF16-BE</li>
803
+     * <li>UTF16-LE</li>
804
+     * <li>UTF8</li>
805
+     * </ul>
806
+     * 
807
+     * @param string $filename
808
+     * @return string|NULL
809
+     */
810 810
     public static function detectUTFBom(string $filename) : ?string
811 811
     {
812 812
         $fp = fopen($filename, 'r');
@@ -838,13 +838,13 @@  discard block
 block discarded – undo
838 838
     
839 839
     protected static $utfBoms;
840 840
     
841
-   /**
842
-    * Retrieves a list of all UTF byte order mark character
843
-    * sequences, as an assocative array with UTF encoding => bom sequence
844
-    * pairs.
845
-    * 
846
-    * @return array
847
-    */
841
+    /**
842
+     * Retrieves a list of all UTF byte order mark character
843
+     * sequences, as an assocative array with UTF encoding => bom sequence
844
+     * pairs.
845
+     * 
846
+     * @return array
847
+     */
848 848
     public static function getUTFBOMs()
849 849
     {
850 850
         if(!isset(self::$utfBoms)) {
@@ -860,15 +860,15 @@  discard block
 block discarded – undo
860 860
         return self::$utfBoms;
861 861
     }
862 862
     
863
-   /**
864
-    * Checks whether the specified encoding is a valid
865
-    * unicode encoding, for example "UTF16-LE" or "UTF8".
866
-    * Also accounts for alternate way to write the, like
867
-    * "UTF-8", and omitting little/big endian suffixes.
868
-    * 
869
-    * @param string $encoding
870
-    * @return boolean
871
-    */
863
+    /**
864
+     * Checks whether the specified encoding is a valid
865
+     * unicode encoding, for example "UTF16-LE" or "UTF8".
866
+     * Also accounts for alternate way to write the, like
867
+     * "UTF-8", and omitting little/big endian suffixes.
868
+     * 
869
+     * @param string $encoding
870
+     * @return boolean
871
+     */
872 872
     public static function isValidUnicodeEncoding(string $encoding) : bool
873 873
     {
874 874
         $encodings = self::getKnownUnicodeEncodings();
@@ -887,40 +887,40 @@  discard block
 block discarded – undo
887 887
         return in_array($encoding, $keep);
888 888
     }
889 889
     
890
-   /**
891
-    * Retrieves a list of all known unicode file encodings.
892
-    * @return array
893
-    */
890
+    /**
891
+     * Retrieves a list of all known unicode file encodings.
892
+     * @return array
893
+     */
894 894
     public static function getKnownUnicodeEncodings()
895 895
     {
896 896
         return array_keys(self::getUTFBOMs());
897 897
     }
898 898
     
899
-   /**
900
-    * Normalizes the slash style in a file or folder path,
901
-    * by replacing any antislashes with forward slashes.
902
-    * 
903
-    * @param string $path
904
-    * @return string
905
-    */
899
+    /**
900
+     * Normalizes the slash style in a file or folder path,
901
+     * by replacing any antislashes with forward slashes.
902
+     * 
903
+     * @param string $path
904
+     * @return string
905
+     */
906 906
     public static function normalizePath(string $path) : string
907 907
     {
908 908
         return str_replace(array('\\', '//'), array('/', '/'), $path);
909 909
     }
910 910
     
911
-   /**
912
-    * Saves the specified data to a file, JSON encoded.
913
-    * 
914
-    * @param mixed $data
915
-    * @param string $file
916
-    * @param bool $pretty
917
-    * @throws FileHelper_Exception
918
-    * 
919
-    * @see FileHelper::ERROR_JSON_ENCODE_ERROR
920
-    * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE
921
-    * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
922
-    * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
923
-    */
911
+    /**
912
+     * Saves the specified data to a file, JSON encoded.
913
+     * 
914
+     * @param mixed $data
915
+     * @param string $file
916
+     * @param bool $pretty
917
+     * @throws FileHelper_Exception
918
+     * 
919
+     * @see FileHelper::ERROR_JSON_ENCODE_ERROR
920
+     * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE
921
+     * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
922
+     * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
923
+     */
924 924
     public static function saveAsJSON($data, string $file, bool $pretty=false)
925 925
     {
926 926
         $options = null;
@@ -944,18 +944,18 @@  discard block
 block discarded – undo
944 944
         self::saveFile($file, $json);
945 945
     }
946 946
    
947
-   /**
948
-    * Saves the specified content to the target file, creating
949
-    * the file and the folder as necessary.
950
-    * 
951
-    * @param string $filePath
952
-    * @param string $content
953
-    * @throws FileHelper_Exception
954
-    * 
955
-    * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE
956
-    * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
957
-    * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
958
-    */
947
+    /**
948
+     * Saves the specified content to the target file, creating
949
+     * the file and the folder as necessary.
950
+     * 
951
+     * @param string $filePath
952
+     * @param string $content
953
+     * @throws FileHelper_Exception
954
+     * 
955
+     * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE
956
+     * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
957
+     * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
958
+     */
959 959
     public static function saveFile(string $filePath, string $content='') : void
960 960
     {
961 961
         // target file already exists
@@ -1008,12 +1008,12 @@  discard block
 block discarded – undo
1008 1008
         );
1009 1009
     }
1010 1010
     
1011
-   /**
1012
-    * Checks whether it is possible to run PHP command 
1013
-    * line commands.
1014
-    * 
1015
-    * @return boolean
1016
-    */
1011
+    /**
1012
+     * Checks whether it is possible to run PHP command 
1013
+     * line commands.
1014
+     * 
1015
+     * @return boolean
1016
+     */
1017 1017
     public static function canMakePHPCalls() : bool
1018 1018
     {
1019 1019
         return self::cliCommandExists('php');
@@ -1090,16 +1090,16 @@  discard block
 block discarded – undo
1090 1090
         return $result;
1091 1091
     }
1092 1092
     
1093
-   /**
1094
-    * Validates a PHP file's syntax.
1095
-    * 
1096
-    * NOTE: This will fail silently if the PHP command line
1097
-    * is not available. Use {@link FileHelper::canMakePHPCalls()}
1098
-    * to check this beforehand as needed.
1099
-    * 
1100
-    * @param string $path
1101
-    * @return boolean|array A boolean true if the file is valid, an array with validation messages otherwise.
1102
-    */
1093
+    /**
1094
+     * Validates a PHP file's syntax.
1095
+     * 
1096
+     * NOTE: This will fail silently if the PHP command line
1097
+     * is not available. Use {@link FileHelper::canMakePHPCalls()}
1098
+     * to check this beforehand as needed.
1099
+     * 
1100
+     * @param string $path
1101
+     * @return boolean|array A boolean true if the file is valid, an array with validation messages otherwise.
1102
+     */
1103 1103
     public static function checkPHPFileSyntax($path)
1104 1104
     {
1105 1105
         if(!self::canMakePHPCalls()) {
@@ -1123,14 +1123,14 @@  discard block
 block discarded – undo
1123 1123
         return $output;
1124 1124
     }
1125 1125
     
1126
-   /**
1127
-    * Retrieves the last modified date for the specified file or folder.
1128
-    * 
1129
-    * Note: If the target does not exist, returns null. 
1130
-    * 
1131
-    * @param string $path
1132
-    * @return \DateTime|NULL
1133
-    */
1126
+    /**
1127
+     * Retrieves the last modified date for the specified file or folder.
1128
+     * 
1129
+     * Note: If the target does not exist, returns null. 
1130
+     * 
1131
+     * @param string $path
1132
+     * @return \DateTime|NULL
1133
+     */
1134 1134
     public static function getModifiedDate($path)
1135 1135
     {
1136 1136
         $time = filemtime($path);
@@ -1143,24 +1143,24 @@  discard block
 block discarded – undo
1143 1143
         return null; 
1144 1144
     }
1145 1145
     
1146
-   /**
1147
-    * Retrieves the names of all subfolders in the specified path.
1148
-    * 
1149
-    * Available options:
1150
-    * 
1151
-    * - recursive: true/false
1152
-    *   Whether to search for subfolders recursively. 
1153
-    *   
1154
-    * - absolute-paths: true/false
1155
-    *   Whether to return a list of absolute paths.
1156
-    * 
1157
-    * @param string $targetFolder
1158
-    * @param array $options
1159
-    * @throws FileHelper_Exception
1160
-    * @return string[]
1161
-    * 
1162
-    * @todo Move this to a separate class.
1163
-    */
1146
+    /**
1147
+     * Retrieves the names of all subfolders in the specified path.
1148
+     * 
1149
+     * Available options:
1150
+     * 
1151
+     * - recursive: true/false
1152
+     *   Whether to search for subfolders recursively. 
1153
+     *   
1154
+     * - absolute-paths: true/false
1155
+     *   Whether to return a list of absolute paths.
1156
+     * 
1157
+     * @param string $targetFolder
1158
+     * @param array $options
1159
+     * @throws FileHelper_Exception
1160
+     * @return string[]
1161
+     * 
1162
+     * @todo Move this to a separate class.
1163
+     */
1164 1164
     public static function getSubfolders($targetFolder, $options = array())
1165 1165
     {
1166 1166
         if(!is_dir($targetFolder)) 
@@ -1221,16 +1221,16 @@  discard block
 block discarded – undo
1221 1221
         return $result;
1222 1222
     }
1223 1223
 
1224
-   /**
1225
-    * Retrieves the maximum allowed upload file size, in bytes.
1226
-    * Takes into account the PHP ini settings <code>post_max_size</code>
1227
-    * and <code>upload_max_filesize</code>. Since these cannot
1228
-    * be modified at runtime, they are the hard limits for uploads.
1229
-    * 
1230
-    * NOTE: Based on binary values, where 1KB = 1024 Bytes.
1231
-    * 
1232
-    * @return int Will return <code>-1</code> if no limit.
1233
-    */
1224
+    /**
1225
+     * Retrieves the maximum allowed upload file size, in bytes.
1226
+     * Takes into account the PHP ini settings <code>post_max_size</code>
1227
+     * and <code>upload_max_filesize</code>. Since these cannot
1228
+     * be modified at runtime, they are the hard limits for uploads.
1229
+     * 
1230
+     * NOTE: Based on binary values, where 1KB = 1024 Bytes.
1231
+     * 
1232
+     * @return int Will return <code>-1</code> if no limit.
1233
+     */
1234 1234
     public static function getMaxUploadFilesize() : int
1235 1235
     {
1236 1236
         static $max_size = -1;
@@ -1267,16 +1267,16 @@  discard block
 block discarded – undo
1267 1267
         return round($size);
1268 1268
     }
1269 1269
    
1270
-   /**
1271
-    * Makes a path relative using a folder depth: will reduce the
1272
-    * length of the path so that only the amount of folders defined
1273
-    * in the <code>$depth</code> attribute are shown below the actual
1274
-    * folder or file in the path.
1275
-    *  
1276
-    * @param string  $path The absolute or relative path
1277
-    * @param int $depth The folder depth to reduce the path to
1278
-    * @return string
1279
-    */
1270
+    /**
1271
+     * Makes a path relative using a folder depth: will reduce the
1272
+     * length of the path so that only the amount of folders defined
1273
+     * in the <code>$depth</code> attribute are shown below the actual
1274
+     * folder or file in the path.
1275
+     *  
1276
+     * @param string  $path The absolute or relative path
1277
+     * @param int $depth The folder depth to reduce the path to
1278
+     * @return string
1279
+     */
1280 1280
     public static function relativizePathByDepth(string $path, int $depth=2) : string
1281 1281
     {
1282 1282
         $path = self::normalizePath($path);
@@ -1314,23 +1314,23 @@  discard block
 block discarded – undo
1314 1314
         return trim(implode('/', $tokens), '/');
1315 1315
     }
1316 1316
     
1317
-   /**
1318
-    * Makes the specified path relative to another path,
1319
-    * by removing one from the other if found. Also 
1320
-    * normalizes the path to use forward slashes. 
1321
-    * 
1322
-    * Example:
1323
-    * 
1324
-    * <pre>
1325
-    * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder');
1326
-    * </pre>
1327
-    * 
1328
-    * Result: <code>to/file.txt</code>
1329
-    * 
1330
-    * @param string $path
1331
-    * @param string $relativeTo
1332
-    * @return string
1333
-    */
1317
+    /**
1318
+     * Makes the specified path relative to another path,
1319
+     * by removing one from the other if found. Also 
1320
+     * normalizes the path to use forward slashes. 
1321
+     * 
1322
+     * Example:
1323
+     * 
1324
+     * <pre>
1325
+     * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder');
1326
+     * </pre>
1327
+     * 
1328
+     * Result: <code>to/file.txt</code>
1329
+     * 
1330
+     * @param string $path
1331
+     * @param string $relativeTo
1332
+     * @return string
1333
+     */
1334 1334
     public static function relativizePath(string $path, string $relativeTo) : string
1335 1335
     {
1336 1336
         $path = self::normalizePath($path);
@@ -1342,17 +1342,17 @@  discard block
 block discarded – undo
1342 1342
         return $relative;
1343 1343
     }
1344 1344
     
1345
-   /**
1346
-    * Checks that the target file exists, and throws an exception
1347
-    * if it does not. 
1348
-    * 
1349
-    * @param string $path
1350
-    * @param int|NULL $errorCode Optional custom error code
1351
-    * @throws FileHelper_Exception
1352
-    * @return string The real path to the file
1353
-    * 
1354
-    * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1355
-    */
1345
+    /**
1346
+     * Checks that the target file exists, and throws an exception
1347
+     * if it does not. 
1348
+     * 
1349
+     * @param string $path
1350
+     * @param int|NULL $errorCode Optional custom error code
1351
+     * @throws FileHelper_Exception
1352
+     * @return string The real path to the file
1353
+     * 
1354
+     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1355
+     */
1356 1356
     public static function requireFileExists(string $path, $errorCode=null) : string
1357 1357
     {
1358 1358
         $result = realpath($path);
@@ -1371,18 +1371,18 @@  discard block
 block discarded – undo
1371 1371
         );
1372 1372
     }
1373 1373
     
1374
-   /**
1375
-    * Reads a specific line number from the target file and returns its
1376
-    * contents, if the file has such a line. Does so with little memory
1377
-    * usage, as the file is not read entirely into memory.
1378
-    * 
1379
-    * @param string $path
1380
-    * @param int $lineNumber Note: 1-based; the first line is number 1.
1381
-    * @return string|NULL Will return null if the requested line does not exist.
1382
-    * @throws FileHelper_Exception
1383
-    * 
1384
-    * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1385
-    */
1374
+    /**
1375
+     * Reads a specific line number from the target file and returns its
1376
+     * contents, if the file has such a line. Does so with little memory
1377
+     * usage, as the file is not read entirely into memory.
1378
+     * 
1379
+     * @param string $path
1380
+     * @param int $lineNumber Note: 1-based; the first line is number 1.
1381
+     * @return string|NULL Will return null if the requested line does not exist.
1382
+     * @throws FileHelper_Exception
1383
+     * 
1384
+     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1385
+     */
1386 1386
     public static function getLineFromFile(string $path, int $lineNumber) : ?string
1387 1387
     {
1388 1388
         self::requireFileExists($path);
@@ -1398,19 +1398,19 @@  discard block
 block discarded – undo
1398 1398
         $file->seek($targetLine);
1399 1399
         
1400 1400
         if($file->key() !== $targetLine) {
1401
-             return null;
1401
+                return null;
1402 1402
         }
1403 1403
         
1404 1404
         return $file->current(); 
1405 1405
     }
1406 1406
     
1407
-   /**
1408
-    * Retrieves the total amount of lines in the file, without 
1409
-    * reading the whole file into memory.
1410
-    * 
1411
-    * @param string $path
1412
-    * @return int
1413
-    */
1407
+    /**
1408
+     * Retrieves the total amount of lines in the file, without 
1409
+     * reading the whole file into memory.
1410
+     * 
1411
+     * @param string $path
1412
+     * @return int
1413
+     */
1414 1414
     public static function countFileLines(string $path) : int
1415 1415
     {
1416 1416
         self::requireFileExists($path);
@@ -1440,26 +1440,26 @@  discard block
 block discarded – undo
1440 1440
         return $number+1;
1441 1441
     }
1442 1442
     
1443
-   /**
1444
-    * Parses the target file to detect any PHP classes contained
1445
-    * within, and retrieve information on them. Does not use the 
1446
-    * PHP reflection API.
1447
-    * 
1448
-    * @param string $filePath
1449
-    * @return FileHelper_PHPClassInfo
1450
-    */
1443
+    /**
1444
+     * Parses the target file to detect any PHP classes contained
1445
+     * within, and retrieve information on them. Does not use the 
1446
+     * PHP reflection API.
1447
+     * 
1448
+     * @param string $filePath
1449
+     * @return FileHelper_PHPClassInfo
1450
+     */
1451 1451
     public static function findPHPClasses(string $filePath) : FileHelper_PHPClassInfo
1452 1452
     {
1453 1453
         return new FileHelper_PHPClassInfo($filePath);
1454 1454
     }
1455 1455
     
1456
-   /**
1457
-    * Detects the end of line style used in the target file, if any.
1458
-    * Can be used with large files, because it only reads part of it.
1459
-    * 
1460
-    * @param string $filePath The path to the file.
1461
-    * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found.
1462
-    */
1456
+    /**
1457
+     * Detects the end of line style used in the target file, if any.
1458
+     * Can be used with large files, because it only reads part of it.
1459
+     * 
1460
+     * @param string $filePath The path to the file.
1461
+     * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found.
1462
+     */
1463 1463
     public static function detectEOLCharacter(string $filePath) : ?ConvertHelper_EOL
1464 1464
     {
1465 1465
         // 20 lines is enough to get a good picture of the newline style in the file.
@@ -1472,18 +1472,18 @@  discard block
 block discarded – undo
1472 1472
         return ConvertHelper::detectEOLCharacter($string);
1473 1473
     }
1474 1474
     
1475
-   /**
1476
-    * Reads the specified amount of lines from the target file.
1477
-    * Unicode BOM compatible: any byte order marker is stripped
1478
-    * from the resulting lines.
1479
-    * 
1480
-    * @param string $filePath
1481
-    * @param int $amount Set to 0 to read all lines.
1482
-    * @return array
1483
-    * 
1484
-    * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES
1485
-    * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1486
-    */
1475
+    /**
1476
+     * Reads the specified amount of lines from the target file.
1477
+     * Unicode BOM compatible: any byte order marker is stripped
1478
+     * from the resulting lines.
1479
+     * 
1480
+     * @param string $filePath
1481
+     * @param int $amount Set to 0 to read all lines.
1482
+     * @return array
1483
+     * 
1484
+     * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES
1485
+     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1486
+     */
1487 1487
     public static function readLines(string $filePath, int $amount=0) : array
1488 1488
     {
1489 1489
         self::requireFileExists($filePath);
@@ -1534,16 +1534,16 @@  discard block
 block discarded – undo
1534 1534
         return $result;
1535 1535
     }
1536 1536
     
1537
-   /**
1538
-    * Reads all content from a file.
1539
-    * 
1540
-    * @param string $filePath
1541
-    * @throws FileHelper_Exception
1542
-    * @return string
1543
-    * 
1544
-    * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1545
-    * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS
1546
-    */
1537
+    /**
1538
+     * Reads all content from a file.
1539
+     * 
1540
+     * @param string $filePath
1541
+     * @throws FileHelper_Exception
1542
+     * @return string
1543
+     * 
1544
+     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1545
+     * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS
1546
+     */
1547 1547
     public static function readContents(string $filePath) : string
1548 1548
     {
1549 1549
         self::requireFileExists($filePath);
Please login to merge, or discard this patch.
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
         
109 109
         $contents = file_get_contents($file);
110 110
         
111
-        if($contents === false) 
111
+        if ($contents === false) 
112 112
         {
113 113
             throw new FileHelper_Exception(
114 114
                 'Cannot load serialized content from file.',
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
         
123 123
         $result = @unserialize($contents);
124 124
         
125
-        if($result !== false) {
125
+        if ($result !== false) {
126 126
             return $result;
127 127
         }
128 128
         
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
     
139 139
     public static function deleteTree($rootFolder)
140 140
     {
141
-        if(!file_exists($rootFolder)) {
141
+        if (!file_exists($rootFolder)) {
142 142
             return true;
143 143
         }
144 144
         
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
     */
180 180
     public static function createFolder($path)
181 181
     {
182
-        if(is_dir($path) || mkdir($path, 0777, true)) {
182
+        if (is_dir($path) || mkdir($path, 0777, true)) {
183 183
             return;
184 184
         }
185 185
         
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
 
215 215
             if ($item->isDir()) 
216 216
             {
217
-                FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target . '/' . $baseName);
217
+                FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target.'/'.$baseName);
218 218
             } 
219
-            else if($item->isFile()) 
219
+            else if ($item->isFile()) 
220 220
             {
221
-                self::copyFile($itemPath, $target . '/' . $baseName);
221
+                self::copyFile($itemPath, $target.'/'.$baseName);
222 222
             }
223 223
         }
224 224
     }
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
     {
244 244
         self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND);
245 245
         
246
-        if(!is_readable($sourcePath))
246
+        if (!is_readable($sourcePath))
247 247
         {
248 248
             throw new FileHelper_Exception(
249 249
                 sprintf('Source file [%s] to copy is not readable.', basename($sourcePath)),
@@ -257,11 +257,11 @@  discard block
 block discarded – undo
257 257
         
258 258
         $targetFolder = dirname($targetPath);
259 259
         
260
-        if(!file_exists($targetFolder))
260
+        if (!file_exists($targetFolder))
261 261
         {
262 262
             self::createFolder($targetFolder);
263 263
         }
264
-        else if(!is_writable($targetFolder)) 
264
+        else if (!is_writable($targetFolder)) 
265 265
         {
266 266
             throw new FileHelper_Exception(
267 267
                 sprintf('Target folder [%s] is not writable.', basename($targetFolder)),
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
             );
274 274
         }
275 275
         
276
-        if(copy($sourcePath, $targetPath)) {
276
+        if (copy($sourcePath, $targetPath)) {
277 277
             return;
278 278
         }
279 279
         
@@ -300,11 +300,11 @@  discard block
 block discarded – undo
300 300
     */
301 301
     public static function deleteFile(string $filePath) : void
302 302
     {
303
-        if(!file_exists($filePath)) {
303
+        if (!file_exists($filePath)) {
304 304
             return;
305 305
         }
306 306
         
307
-        if(unlink($filePath)) {
307
+        if (unlink($filePath)) {
308 308
             return;
309 309
         }
310 310
         
@@ -328,10 +328,10 @@  discard block
 block discarded – undo
328 328
     * @return \parseCSV
329 329
     * @todo Move this to the CSV helper.
330 330
     */
331
-    public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : \parseCSV
331
+    public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : \parseCSV
332 332
     {
333
-        if($delimiter==='') { $delimiter = ';'; }
334
-        if($enclosure==='') { $enclosure = '"'; }
333
+        if ($delimiter === '') { $delimiter = ';'; }
334
+        if ($enclosure === '') { $enclosure = '"'; }
335 335
         
336 336
         $parser = new \parseCSV(null, null, null, array());
337 337
 
@@ -359,11 +359,11 @@  discard block
 block discarded – undo
359 359
     * @see parseCSVFile()
360 360
     * @see FileHelper::ERROR_PARSING_CSV
361 361
     */
362
-    public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array
362
+    public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array
363 363
     {
364 364
         $parser = self::createCSVParser($delimiter, $enclosure, $escape, $heading);
365 365
         $result = $parser->parse_string(/** @scrutinizer ignore-type */ $csv);
366
-        if(is_array($result)) {
366
+        if (is_array($result)) {
367 367
             return $result;
368 368
         }
369 369
         
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
      * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
392 392
      * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS
393 393
      */
394
-    public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array
394
+    public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array
395 395
     {
396 396
         $content = self::readContents($filePath);
397 397
 
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
     public static function detectMimeType(string $fileName) : ?string
409 409
     {
410 410
         $ext = self::getExtension($fileName);
411
-        if(empty($ext)) {
411
+        if (empty($ext)) {
412 412
             return null;
413 413
         }
414 414
 
@@ -429,11 +429,11 @@  discard block
 block discarded – undo
429 429
      * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
430 430
      * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE
431 431
      */
432
-    public static function sendFile(string $filePath, $fileName = null, bool $asAttachment=true)
432
+    public static function sendFile(string $filePath, $fileName = null, bool $asAttachment = true)
433 433
     {
434 434
         self::requireFileExists($filePath);
435 435
         
436
-        if(empty($fileName)) {
436
+        if (empty($fileName)) {
437 437
             $fileName = basename($filePath);
438 438
         }
439 439
 
@@ -451,10 +451,10 @@  discard block
 block discarded – undo
451 451
         
452 452
         header("Cache-Control: public", true);
453 453
         header("Content-Description: File Transfer", true);
454
-        header("Content-Type: " . $mime, true);
454
+        header("Content-Type: ".$mime, true);
455 455
 
456 456
         $disposition = 'inline';
457
-        if($asAttachment) {
457
+        if ($asAttachment) {
458 458
             $disposition = 'attachment';
459 459
         }
460 460
         
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
      */
481 481
     public static function downloadFile($url)
482 482
     {
483
-        if(!function_exists('curl_init')) 
483
+        if (!function_exists('curl_init')) 
484 484
         {
485 485
             throw new FileHelper_Exception(
486 486
                 'The cURL extension is not installed.',
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
         }
491 491
 
492 492
         $ch = curl_init();
493
-        if($ch === false) 
493
+        if ($ch === false) 
494 494
         {
495 495
             throw new FileHelper_Exception(
496 496
                 'Could not initialize a new cURL instance.',
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
         
512 512
         $output = curl_exec($ch);
513 513
 
514
-        if($output === false) {
514
+        if ($output === false) {
515 515
             throw new FileHelper_Exception(
516 516
                 'Unable to open URL',
517 517
                 sprintf(
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
 
526 526
         curl_close($ch);
527 527
 
528
-        if(is_string($output)) 
528
+        if (is_string($output)) 
529 529
         {
530 530
             return $output;
531 531
         }
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
     */
548 548
     public static function isPHPFile($pathOrDirIterator)
549 549
     {
550
-    	if(self::getExtension($pathOrDirIterator) == 'php') {
550
+    	if (self::getExtension($pathOrDirIterator) == 'php') {
551 551
     		return true;
552 552
     	}
553 553
     	
@@ -564,14 +564,14 @@  discard block
 block discarded – undo
564 564
     */
565 565
     public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string
566 566
     {
567
-        if($pathOrDirIterator instanceof \DirectoryIterator) {
567
+        if ($pathOrDirIterator instanceof \DirectoryIterator) {
568 568
             $filename = $pathOrDirIterator->getFilename();
569 569
         } else {
570 570
             $filename = basename($pathOrDirIterator);
571 571
         }
572 572
          
573 573
         $ext = pathinfo($filename, PATHINFO_EXTENSION);
574
-        if($lowercase) {
574
+        if ($lowercase) {
575 575
         	$ext = mb_strtolower($ext);
576 576
         }
577 577
         
@@ -593,13 +593,13 @@  discard block
 block discarded – undo
593 593
     public static function getFilename($pathOrDirIterator, $extension = true)
594 594
     {
595 595
         $path = $pathOrDirIterator;
596
-    	if($pathOrDirIterator instanceof \DirectoryIterator) {
596
+    	if ($pathOrDirIterator instanceof \DirectoryIterator) {
597 597
     		$path = $pathOrDirIterator->getFilename();
598 598
     	}
599 599
     	
600 600
     	$path = self::normalizePath($path);
601 601
     	
602
-    	if(!$extension) {
602
+    	if (!$extension) {
603 603
     	    return pathinfo($path, PATHINFO_FILENAME);
604 604
     	}
605 605
     	
@@ -617,12 +617,12 @@  discard block
 block discarded – undo
617 617
     * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE
618 618
     * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE
619 619
     */ 
620
-    public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null)
620
+    public static function parseJSONFile(string $file, $targetEncoding = null, $sourceEncoding = null)
621 621
     {
622 622
         self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE);
623 623
         
624 624
         $content = file_get_contents($file);
625
-        if(!$content) {
625
+        if (!$content) {
626 626
             throw new FileHelper_Exception(
627 627
                 'Cannot get file contents',
628 628
                 sprintf(
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
             );
634 634
         }
635 635
         
636
-        if(isset($targetEncoding)) {
636
+        if (isset($targetEncoding)) {
637 637
             $content = mb_convert_encoding($content, $targetEncoding, $sourceEncoding);
638 638
         }
639 639
         
640 640
         $json = json_decode($content, true);
641
-        if($json === false || $json === NULL) {
641
+        if ($json === false || $json === NULL) {
642 642
             throw new FileHelper_Exception(
643 643
                 'Cannot decode json data',
644 644
                 sprintf(
@@ -678,13 +678,13 @@  discard block
 block discarded – undo
678 678
         
679 679
         $name = str_replace(array_keys($replaces), array_values($replaces), $name);
680 680
         
681
-        while(strstr($name, '  ')) {
681
+        while (strstr($name, '  ')) {
682 682
             $name = str_replace('  ', ' ', $name);
683 683
         }
684 684
 
685 685
         $name = str_replace(array_keys($replaces), array_values($replaces), $name);
686 686
         
687
-        while(strstr($name, '..')) {
687
+        while (strstr($name, '..')) {
688 688
             $name = str_replace('..', '.', $name);
689 689
         }
690 690
         
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
     * @return array An indexed array with files.
717 717
     * @see FileHelper::createFileFinder()
718 718
     */
719
-    public static function findHTMLFiles(string $targetFolder, array $options=array()) : array
719
+    public static function findHTMLFiles(string $targetFolder, array $options = array()) : array
720 720
     {
721 721
         return self::findFiles($targetFolder, array('html'), $options);
722 722
     }
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
     * @return array An indexed array of PHP files.
734 734
     * @see FileHelper::createFileFinder()
735 735
     */
736
-    public static function findPHPFiles(string $targetFolder, array $options=array()) : array
736
+    public static function findPHPFiles(string $targetFolder, array $options = array()) : array
737 737
     {
738 738
         return self::findFiles($targetFolder, array('php'), $options);
739 739
     }
@@ -753,20 +753,20 @@  discard block
 block discarded – undo
753 753
     * @return array
754 754
     * @see FileHelper::createFileFinder()
755 755
     */
756
-    public static function findFiles(string $targetFolder, array $extensions=array(), array $options=array(), array $files=array()) : array
756
+    public static function findFiles(string $targetFolder, array $extensions = array(), array $options = array(), array $files = array()) : array
757 757
     {
758 758
         $finder = self::createFileFinder($targetFolder);
759 759
 
760
-        if(isset($options['relative-path']) && $options['relative-path'] === true) 
760
+        if (isset($options['relative-path']) && $options['relative-path'] === true) 
761 761
         {
762 762
             $finder->setPathmodeRelative();
763 763
         } 
764
-        else if(isset($options['absolute-path']) && $options['absolute-path'] === true)
764
+        else if (isset($options['absolute-path']) && $options['absolute-path'] === true)
765 765
         {
766 766
             $finder->setPathmodeAbsolute();
767 767
         }
768 768
         
769
-        if(isset($options['strip-extension'])) 
769
+        if (isset($options['strip-extension'])) 
770 770
         {
771 771
             $finder->stripExtensions();
772 772
         }
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
     public static function detectUTFBom(string $filename) : ?string
811 811
     {
812 812
         $fp = fopen($filename, 'r');
813
-        if($fp === false) 
813
+        if ($fp === false) 
814 814
         {
815 815
             throw new FileHelper_Exception(
816 816
                 'Cannot open file for reading',
@@ -825,10 +825,10 @@  discard block
 block discarded – undo
825 825
 
826 826
         $boms = self::getUTFBOMs();
827 827
         
828
-        foreach($boms as $bom => $value) 
828
+        foreach ($boms as $bom => $value) 
829 829
         {
830 830
             $length = mb_strlen($value);
831
-            if(mb_substr($text, 0, $length) == $value) {
831
+            if (mb_substr($text, 0, $length) == $value) {
832 832
                 return $bom;
833 833
             }
834 834
         }
@@ -847,13 +847,13 @@  discard block
 block discarded – undo
847 847
     */
848 848
     public static function getUTFBOMs()
849 849
     {
850
-        if(!isset(self::$utfBoms)) {
850
+        if (!isset(self::$utfBoms)) {
851 851
             self::$utfBoms = array(
852
-                'UTF32-BE' => chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF),
853
-                'UTF32-LE' => chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00),
854
-                'UTF16-BE' => chr(0xFE) . chr(0xFF),
855
-                'UTF16-LE' => chr(0xFF) . chr(0xFE),
856
-                'UTF8' => chr(0xEF) . chr(0xBB) . chr(0xBF)
852
+                'UTF32-BE' => chr(0x00).chr(0x00).chr(0xFE).chr(0xFF),
853
+                'UTF32-LE' => chr(0xFF).chr(0xFE).chr(0x00).chr(0x00),
854
+                'UTF16-BE' => chr(0xFE).chr(0xFF),
855
+                'UTF16-LE' => chr(0xFF).chr(0xFE),
856
+                'UTF8' => chr(0xEF).chr(0xBB).chr(0xBF)
857 857
             );
858 858
         }
859 859
         
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
         $encodings = self::getKnownUnicodeEncodings();
875 875
 
876 876
         $keep = array();
877
-        foreach($encodings as $string) 
877
+        foreach ($encodings as $string) 
878 878
         {
879 879
             $withHyphen = str_replace('UTF', 'UTF-', $string);
880 880
             
@@ -921,16 +921,16 @@  discard block
 block discarded – undo
921 921
     * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
922 922
     * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
923 923
     */
924
-    public static function saveAsJSON($data, string $file, bool $pretty=false)
924
+    public static function saveAsJSON($data, string $file, bool $pretty = false)
925 925
     {
926 926
         $options = null;
927
-        if($pretty) {
927
+        if ($pretty) {
928 928
             $options = JSON_PRETTY_PRINT;
929 929
         }
930 930
         
931 931
         $json = json_encode($data, $options);
932 932
         
933
-        if($json===false) 
933
+        if ($json === false) 
934 934
         {
935 935
             $errorCode = json_last_error();
936 936
             
@@ -956,12 +956,12 @@  discard block
 block discarded – undo
956 956
     * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
957 957
     * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
958 958
     */
959
-    public static function saveFile(string $filePath, string $content='') : void
959
+    public static function saveFile(string $filePath, string $content = '') : void
960 960
     {
961 961
         // target file already exists
962
-        if(file_exists($filePath))
962
+        if (file_exists($filePath))
963 963
         {
964
-            if(!is_writable($filePath))
964
+            if (!is_writable($filePath))
965 965
             {
966 966
                 throw new FileHelper_Exception(
967 967
                     sprintf('Cannot save file: target file [%s] exists, but is not writable.', basename($filePath)),
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
             // create the folder as needed
982 982
             self::createFolder($targetFolder);
983 983
             
984
-            if(!is_writable($targetFolder)) 
984
+            if (!is_writable($targetFolder)) 
985 985
             {
986 986
                 throw new FileHelper_Exception(
987 987
                     sprintf('Cannot save file: target folder [%s] is not writable.', basename($targetFolder)),
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
             }
995 995
         }
996 996
         
997
-        if(file_put_contents($filePath, $content) !== false) {
997
+        if (file_put_contents($filePath, $content) !== false) {
998 998
             return;
999 999
         }
1000 1000
         
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
     {
1033 1033
         static $checked = array();
1034 1034
         
1035
-        if(isset($checked[$command])) {
1035
+        if (isset($checked[$command])) {
1036 1036
             return $checked[$command];
1037 1037
         }
1038 1038
         
@@ -1045,7 +1045,7 @@  discard block
 block discarded – undo
1045 1045
         
1046 1046
         $os = strtolower(PHP_OS_FAMILY);
1047 1047
         
1048
-        if(!isset($osCommands[$os])) 
1048
+        if (!isset($osCommands[$os])) 
1049 1049
         {
1050 1050
             throw new FileHelper_Exception(
1051 1051
                 'Unsupported OS for CLI commands',
@@ -1071,7 +1071,7 @@  discard block
 block discarded – undo
1071 1071
             $pipes
1072 1072
         );
1073 1073
         
1074
-        if($process === false) {
1074
+        if ($process === false) {
1075 1075
             $checked[$command] = false;
1076 1076
             return false;
1077 1077
         }
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
     */
1103 1103
     public static function checkPHPFileSyntax($path)
1104 1104
     {
1105
-        if(!self::canMakePHPCalls()) {
1105
+        if (!self::canMakePHPCalls()) {
1106 1106
             return true;
1107 1107
         }
1108 1108
         
@@ -1113,7 +1113,7 @@  discard block
 block discarded – undo
1113 1113
         // when the validation is successful, the first entry
1114 1114
         // in the array contains the success message. When it
1115 1115
         // is invalid, the first entry is always empty.
1116
-        if(!empty($output[0])) {
1116
+        if (!empty($output[0])) {
1117 1117
             return true;
1118 1118
         }
1119 1119
         
@@ -1134,7 +1134,7 @@  discard block
 block discarded – undo
1134 1134
     public static function getModifiedDate($path)
1135 1135
     {
1136 1136
         $time = filemtime($path);
1137
-        if($time !== false) {
1137
+        if ($time !== false) {
1138 1138
             $date = new \DateTime();
1139 1139
             $date->setTimestamp($time);
1140 1140
             return $date;
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
     */
1164 1164
     public static function getSubfolders($targetFolder, $options = array())
1165 1165
     {
1166
-        if(!is_dir($targetFolder)) 
1166
+        if (!is_dir($targetFolder)) 
1167 1167
         {
1168 1168
             throw new FileHelper_Exception(
1169 1169
                 'Target folder does not exist',
@@ -1187,29 +1187,29 @@  discard block
 block discarded – undo
1187 1187
         
1188 1188
         $d = new \DirectoryIterator($targetFolder);
1189 1189
         
1190
-        foreach($d as $item) 
1190
+        foreach ($d as $item) 
1191 1191
         {
1192
-            if($item->isDir() && !$item->isDot()) 
1192
+            if ($item->isDir() && !$item->isDot()) 
1193 1193
             {
1194 1194
                 $name = $item->getFilename();
1195 1195
                 
1196
-                if(!$options['absolute-path']) {
1196
+                if (!$options['absolute-path']) {
1197 1197
                     $result[] = $name;
1198 1198
                 } else {
1199 1199
                     $result[] = $targetFolder.'/'.$name;
1200 1200
                 }
1201 1201
                 
1202
-                if(!$options['recursive']) 
1202
+                if (!$options['recursive']) 
1203 1203
                 {
1204 1204
                     continue;
1205 1205
                 }
1206 1206
                 
1207 1207
                 $subs = self::getSubfolders($targetFolder.'/'.$name, $options);
1208
-                foreach($subs as $sub) 
1208
+                foreach ($subs as $sub) 
1209 1209
                 {
1210 1210
                     $relative = $name.'/'.$sub;
1211 1211
                     
1212
-                    if(!$options['absolute-path']) {
1212
+                    if (!$options['absolute-path']) {
1213 1213
                         $result[] = $relative;
1214 1214
                     } else {
1215 1215
                         $result[] = $targetFolder.'/'.$relative;
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
     * @param int $depth The folder depth to reduce the path to
1278 1278
     * @return string
1279 1279
     */
1280
-    public static function relativizePathByDepth(string $path, int $depth=2) : string
1280
+    public static function relativizePathByDepth(string $path, int $depth = 2) : string
1281 1281
     {
1282 1282
         $path = self::normalizePath($path);
1283 1283
         
@@ -1285,17 +1285,17 @@  discard block
 block discarded – undo
1285 1285
         $tokens = array_filter($tokens); // remove empty entries (trailing slash for example)
1286 1286
         $tokens = array_values($tokens); // re-index keys
1287 1287
         
1288
-        if(empty($tokens)) {
1288
+        if (empty($tokens)) {
1289 1289
             return '';
1290 1290
         }
1291 1291
         
1292 1292
         // remove the drive if present
1293
-        if(strstr($tokens[0], ':')) {
1293
+        if (strstr($tokens[0], ':')) {
1294 1294
             array_shift($tokens);
1295 1295
         }
1296 1296
         
1297 1297
         // path was only the drive
1298
-        if(count($tokens) == 0) {
1298
+        if (count($tokens) == 0) {
1299 1299
             return '';
1300 1300
         }
1301 1301
 
@@ -1304,8 +1304,8 @@  discard block
 block discarded – undo
1304 1304
         
1305 1305
         // reduce the path to the specified depth
1306 1306
         $length = count($tokens);
1307
-        if($length > $depth) {
1308
-            $tokens = array_slice($tokens, $length-$depth);
1307
+        if ($length > $depth) {
1308
+            $tokens = array_slice($tokens, $length - $depth);
1309 1309
         }
1310 1310
 
1311 1311
         // append the last element again
@@ -1353,14 +1353,14 @@  discard block
 block discarded – undo
1353 1353
     * 
1354 1354
     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1355 1355
     */
1356
-    public static function requireFileExists(string $path, $errorCode=null) : string
1356
+    public static function requireFileExists(string $path, $errorCode = null) : string
1357 1357
     {
1358 1358
         $result = realpath($path);
1359
-        if($result !== false) {
1359
+        if ($result !== false) {
1360 1360
             return $result;
1361 1361
         }
1362 1362
         
1363
-        if($errorCode === null) {
1363
+        if ($errorCode === null) {
1364 1364
             $errorCode = self::ERROR_FILE_DOES_NOT_EXIST;
1365 1365
         }
1366 1366
         
@@ -1389,15 +1389,15 @@  discard block
 block discarded – undo
1389 1389
         
1390 1390
         $file = new \SplFileObject($path);
1391 1391
         
1392
-        if($file->eof()) {
1392
+        if ($file->eof()) {
1393 1393
             return '';
1394 1394
         }
1395 1395
         
1396
-        $targetLine = $lineNumber-1;
1396
+        $targetLine = $lineNumber - 1;
1397 1397
         
1398 1398
         $file->seek($targetLine);
1399 1399
         
1400
-        if($file->key() !== $targetLine) {
1400
+        if ($file->key() !== $targetLine) {
1401 1401
              return null;
1402 1402
         }
1403 1403
         
@@ -1423,7 +1423,7 @@  discard block
 block discarded – undo
1423 1423
         $number = $spl->key();
1424 1424
         
1425 1425
         // if seeking to the end the cursor is still at 0, there are no lines. 
1426
-        if($number === 0) 
1426
+        if ($number === 0) 
1427 1427
         {
1428 1428
             // since it's a very small file, to get reliable results,
1429 1429
             // we read its contents and use that to determine what
@@ -1431,13 +1431,13 @@  discard block
 block discarded – undo
1431 1431
             // that this is not pactical to solve with the SplFileObject.
1432 1432
             $content = file_get_contents($path);
1433 1433
             
1434
-            if(empty($content)) {
1434
+            if (empty($content)) {
1435 1435
                 return 0;
1436 1436
             }
1437 1437
         }
1438 1438
         
1439 1439
         // return the line number we were able to reach + 1 (key is zero-based)
1440
-        return $number+1;
1440
+        return $number + 1;
1441 1441
     }
1442 1442
     
1443 1443
    /**
@@ -1484,13 +1484,13 @@  discard block
 block discarded – undo
1484 1484
     * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES
1485 1485
     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1486 1486
     */
1487
-    public static function readLines(string $filePath, int $amount=0) : array
1487
+    public static function readLines(string $filePath, int $amount = 0) : array
1488 1488
     {
1489 1489
         self::requireFileExists($filePath);
1490 1490
         
1491 1491
         $fn = fopen($filePath, "r");
1492 1492
         
1493
-        if($fn === false) 
1493
+        if ($fn === false) 
1494 1494
         {
1495 1495
             throw new FileHelper_Exception(
1496 1496
                 'Could not open file for reading.',
@@ -1506,25 +1506,25 @@  discard block
 block discarded – undo
1506 1506
         $counter = 0;
1507 1507
         $first = true;
1508 1508
         
1509
-        while(!feof($fn)) 
1509
+        while (!feof($fn)) 
1510 1510
         {
1511 1511
             $counter++;
1512 1512
             
1513 1513
             $line = fgets($fn);
1514 1514
             
1515 1515
             // can happen with zero length files
1516
-            if($line === false) {
1516
+            if ($line === false) {
1517 1517
                 continue;
1518 1518
             }
1519 1519
             
1520 1520
             // the first line may contain a unicode BOM marker.
1521
-            if($first) {
1521
+            if ($first) {
1522 1522
                 $line = ConvertHelper::stripUTFBom($line);
1523 1523
             }
1524 1524
             
1525 1525
             $result[] = $line;
1526 1526
             
1527
-            if($amount > 0 && $counter == $amount) {
1527
+            if ($amount > 0 && $counter == $amount) {
1528 1528
                 break;
1529 1529
             }
1530 1530
         }
@@ -1550,7 +1550,7 @@  discard block
 block discarded – undo
1550 1550
         
1551 1551
         $result = file_get_contents($filePath);
1552 1552
         
1553
-        if($result !== false) {
1553
+        if ($result !== false) {
1554 1554
             return $result;
1555 1555
         }
1556 1556
         
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -215,8 +215,7 @@  discard block
 block discarded – undo
215 215
             if ($item->isDir()) 
216 216
             {
217 217
                 FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target . '/' . $baseName);
218
-            } 
219
-            else if($item->isFile()) 
218
+            } else if($item->isFile()) 
220 219
             {
221 220
                 self::copyFile($itemPath, $target . '/' . $baseName);
222 221
             }
@@ -260,8 +259,7 @@  discard block
 block discarded – undo
260 259
         if(!file_exists($targetFolder))
261 260
         {
262 261
             self::createFolder($targetFolder);
263
-        }
264
-        else if(!is_writable($targetFolder)) 
262
+        } else if(!is_writable($targetFolder)) 
265 263
         {
266 264
             throw new FileHelper_Exception(
267 265
                 sprintf('Target folder [%s] is not writable.', basename($targetFolder)),
@@ -760,8 +758,7 @@  discard block
 block discarded – undo
760 758
         if(isset($options['relative-path']) && $options['relative-path'] === true) 
761 759
         {
762 760
             $finder->setPathmodeRelative();
763
-        } 
764
-        else if(isset($options['absolute-path']) && $options['absolute-path'] === true)
761
+        } else if(isset($options['absolute-path']) && $options['absolute-path'] === true)
765 762
         {
766 763
             $finder->setPathmodeAbsolute();
767 764
         }
Please login to merge, or discard this patch.
src/Request/Param/Filter.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@
 block discarded – undo
22 22
 {
23 23
     use Traits_Optionable;
24 24
     
25
-   /**
26
-    * @var Request_Param
27
-    */
25
+    /**
26
+     * @var Request_Param
27
+     */
28 28
     protected $param;
29 29
     
30 30
     protected $value;
Please login to merge, or discard this patch.
src/Request/Param/Filter/Boolean.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
     
21 21
     protected function _filter()
22 22
     {
23
-        if($this->value === 'yes' || $this->value === 'true' || $this->value === true) {
23
+        if ($this->value === 'yes' || $this->value === 'true' || $this->value === true) {
24 24
             return true;
25 25
         }
26 26
         
Please login to merge, or discard this patch.
src/Request/Param/Filter/CommaSeparated.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
     
24 24
     protected function _filter()
25 25
     {
26
-        if(is_array($this->value)) {
26
+        if (is_array($this->value)) {
27 27
             return $this->value;
28 28
         }
29 29
         
30
-        if($this->value === '' || $this->value === null || !is_string($this->value)) {
30
+        if ($this->value === '' || $this->value === null || !is_string($this->value)) {
31 31
             return array();
32 32
         }
33 33
         
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
         $stripEmptyEntries = $this->getBoolOption('stripEmptyEntries');
36 36
         $result = explode(',', $this->value);
37 37
         
38
-        if(!$trimEntries && !$stripEmptyEntries) {
38
+        if (!$trimEntries && !$stripEmptyEntries) {
39 39
             return $result;
40 40
         }
41 41
         
42 42
         $keep = array();
43 43
         
44
-        foreach($result as $entry)
44
+        foreach ($result as $entry)
45 45
         {
46
-            if($trimEntries === true) {
46
+            if ($trimEntries === true) {
47 47
                 $entry = trim($entry);
48 48
             }
49 49
             
50
-            if($stripEmptyEntries === true && $entry === '') {
50
+            if ($stripEmptyEntries === true && $entry === '') {
51 51
                 continue;
52 52
             }
53 53
             
Please login to merge, or discard this patch.
src/Request/Param/Filter/String.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
     
21 21
     protected function _filter()
22 22
     {
23
-        if(!is_scalar($this->value)) {
23
+        if (!is_scalar($this->value)) {
24 24
             return '';
25 25
         }
26 26
         
Please login to merge, or discard this patch.
src/Request/Param/Validator/Alpha.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,11 +27,11 @@
 block discarded – undo
27 27
     
28 28
     protected function _validate()
29 29
     {
30
-        if(!is_scalar($this->value)) {
30
+        if (!is_scalar($this->value)) {
31 31
             return null;
32 32
         }
33 33
         
34
-        if(preg_match('/\A[a-zA-Z]+\z/', $this->value)) {
34
+        if (preg_match('/\A[a-zA-Z]+\z/', $this->value)) {
35 35
             return $this->value;
36 36
         }
37 37
         
Please login to merge, or discard this patch.
src/Request/Param/Validator/Callback.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
         array_unshift($args, $this->value);
35 35
         
36 36
         $result = call_user_func_array($this->getOption('callback'), $args);
37
-        if($result !== false) {
37
+        if ($result !== false) {
38 38
             return $this->value;
39 39
         }
40 40
         
Please login to merge, or discard this patch.