Passed
Push — master ( 428f46...c925bb )
by Sebastian
02:32
created
src/IniHelper.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -35,12 +35,12 @@  discard block
 block discarded – undo
35 35
     {
36 36
         $section = $this->addSection(self::SECTION_DEFAULT);
37 37
         
38
-        if(empty($iniString)) {
38
+        if (empty($iniString)) {
39 39
             return;
40 40
         }
41 41
         
42 42
         $eol = ConvertHelper::detectEOLCharacter($iniString);
43
-        if($eol !== null) {
43
+        if ($eol !== null) {
44 44
             $this->eol = $eol->getCharacter();
45 45
         }
46 46
         
@@ -48,11 +48,11 @@  discard block
 block discarded – undo
48 48
         
49 49
         $total = count($lines);
50 50
         
51
-        for($i=0; $i < $total; $i++) 
51
+        for ($i = 0; $i < $total; $i++) 
52 52
         {
53 53
             $line = new IniHelper_Line($lines[$i], $i);
54 54
             
55
-            if($line->isSection()) {
55
+            if ($line->isSection()) {
56 56
                 $section = $this->addSection($line->getSectionName());
57 57
             }
58 58
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
         $iniPath = FileHelper::requireFileExists($iniPath);
83 83
         
84 84
         $content = file_get_contents($iniPath);
85
-        if($content !== false) {
85
+        if ($content !== false) {
86 86
             return self::createFromString($content);
87 87
         }
88 88
         
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
     */
128 128
     public function addSection(string $name) : IniHelper_Section
129 129
     {
130
-        if(!isset($this->sections[$name])) {
130
+        if (!isset($this->sections[$name])) {
131 131
             $this->sections[$name] = new IniHelper_Section($this, $name);
132 132
         }
133 133
         
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
     */
143 143
     public function getSection(string $name) : ?IniHelper_Section
144 144
     {
145
-        if(isset($this->sections[$name])) {
145
+        if (isset($this->sections[$name])) {
146 146
             return $this->sections[$name];
147 147
         }
148 148
         
@@ -158,9 +158,9 @@  discard block
 block discarded – undo
158 158
     {
159 159
         $result = array();
160 160
         
161
-        foreach($this->sections as $section)
161
+        foreach ($this->sections as $section)
162 162
         {
163
-            if($section->isDefault()) 
163
+            if ($section->isDefault()) 
164 164
             {
165 165
                 $result = array_merge($result, $section->toArray());
166 166
             } 
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
     {
201 201
         $parts = array();
202 202
         
203
-        foreach($this->sections as $section)
203
+        foreach ($this->sections as $section)
204 204
         {
205 205
             $parts[] = $section->toString();
206 206
         }
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
     */
244 244
     public function sectionExists(string $name) : bool
245 245
     {
246
-        foreach($this->sections as $section) {
247
-            if($section->getName() === $name) {
246
+        foreach ($this->sections as $section) {
247
+            if ($section->getName() === $name) {
248 248
                 return true;
249 249
             }
250 250
         }
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
     {
274 274
         $path = $this->parsePath($path);
275 275
         
276
-        if(!$this->sectionExists($path['section'])) {
276
+        if (!$this->sectionExists($path['section'])) {
277 277
             return array();
278 278
         }
279 279
         
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
     {
285 285
         $path = explode($this->pathSeparator, $path);
286 286
         
287
-        if(count($path) === 1)
287
+        if (count($path) === 1)
288 288
         {
289 289
             return array(
290 290
                 'section' => self::SECTION_DEFAULT,
Please login to merge, or discard this patch.
src/Traits/Optionable.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     */
42 42
     public function setOption(string $name, $value) : Interface_Optionable
43 43
     {
44
-        if(!isset($this->options)) {
44
+        if (!isset($this->options)) {
45 45
             $this->options = $this->getDefaultOptions();
46 46
         }
47 47
         
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
     */
59 59
     public function setOptions(array $options) : Interface_Optionable
60 60
     {
61
-        foreach($options as $name => $value) {
61
+        foreach ($options as $name => $value) {
62 62
             $this->setOption($name, $value);
63 63
         }
64 64
         
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
     * @param mixed $default The default value to return if the option does not exist.
76 76
     * @return mixed
77 77
     */
78
-    public function getOption(string $name, $default=null)
78
+    public function getOption(string $name, $default = null)
79 79
     {
80
-        if(!isset($this->options)) {
80
+        if (!isset($this->options)) {
81 81
             $this->options = $this->getDefaultOptions();
82 82
         }
83 83
         
84
-        if(isset($this->options[$name])) {
84
+        if (isset($this->options[$name])) {
85 85
             return $this->options[$name];
86 86
         }
87 87
         
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
     {
101 101
         $value = $this->getOption($name, false);
102 102
         
103
-        if(is_scalar($value)) {
103
+        if (is_scalar($value)) {
104 104
             return (string)$value;
105 105
         }
106 106
         
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     */
119 119
     public function getBoolOption(string $name) : bool
120 120
     {
121
-        if($this->getOption($name) === true) {
121
+        if ($this->getOption($name) === true) {
122 122
             return true;
123 123
         }
124 124
         
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
     public function getArrayOption(string $name) : array
137 137
     {
138 138
         $val = $this->getOption($name);
139
-        if(is_array($val)) {
139
+        if (is_array($val)) {
140 140
             return $val;
141 141
         }
142 142
         
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
     */
153 153
     public function hasOption(string $name) : bool
154 154
     {
155
-        if(!isset($this->options)) {
155
+        if (!isset($this->options)) {
156 156
             $this->options = $this->getDefaultOptions();
157 157
         }
158 158
         
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
     */
166 166
     public function getOptions() : array
167 167
     {
168
-        if(!isset($this->options)) {
168
+        if (!isset($this->options)) {
169 169
             $this->options = $this->getDefaultOptions();
170 170
         }
171 171
         
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 interface Interface_Optionable
201 201
 {
202 202
     function setOption(string $name, $value) : Interface_Optionable;
203
-    function getOption(string $name, $default=null);
203
+    function getOption(string $name, $default = null);
204 204
     function setOptions(array $options) : Interface_Optionable;
205 205
     function getOptions() : array;
206 206
     function isOption(string $name, $value) : bool;
Please login to merge, or discard this patch.
src/FileHelper.php 1 patch
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
         
111 111
         $contents = file_get_contents($file);
112 112
         
113
-        if($contents === false) 
113
+        if ($contents === false) 
114 114
         {
115 115
             throw new FileHelper_Exception(
116 116
                 'Cannot load serialized content from file.',
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
         
125 125
         $result = @unserialize($contents);
126 126
         
127
-        if($result !== false) {
127
+        if ($result !== false) {
128 128
             return $result;
129 129
         }
130 130
         
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
     
141 141
     public static function deleteTree($rootFolder)
142 142
     {
143
-        if(!file_exists($rootFolder)) {
143
+        if (!file_exists($rootFolder)) {
144 144
             return true;
145 145
         }
146 146
         
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
     */
182 182
     public static function createFolder($path)
183 183
     {
184
-        if(is_dir($path) || mkdir($path, 0777, true)) {
184
+        if (is_dir($path) || mkdir($path, 0777, true)) {
185 185
             return;
186 186
         }
187 187
         
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
 
217 217
             if ($item->isDir()) 
218 218
             {
219
-                FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target . '/' . $baseName);
219
+                FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target.'/'.$baseName);
220 220
             } 
221
-            else if($item->isFile()) 
221
+            else if ($item->isFile()) 
222 222
             {
223
-                self::copyFile($itemPath, $target . '/' . $baseName);
223
+                self::copyFile($itemPath, $target.'/'.$baseName);
224 224
             }
225 225
         }
226 226
     }
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
     {
246 246
         self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND);
247 247
         
248
-        if(!is_readable($sourcePath))
248
+        if (!is_readable($sourcePath))
249 249
         {
250 250
             throw new FileHelper_Exception(
251 251
                 sprintf('Source file [%s] to copy is not readable.', basename($sourcePath)),
@@ -259,11 +259,11 @@  discard block
 block discarded – undo
259 259
         
260 260
         $targetFolder = dirname($targetPath);
261 261
         
262
-        if(!file_exists($targetFolder))
262
+        if (!file_exists($targetFolder))
263 263
         {
264 264
             self::createFolder($targetFolder);
265 265
         }
266
-        else if(!is_writable($targetFolder)) 
266
+        else if (!is_writable($targetFolder)) 
267 267
         {
268 268
             throw new FileHelper_Exception(
269 269
                 sprintf('Target folder [%s] is not writable.', basename($targetFolder)),
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
             );
276 276
         }
277 277
         
278
-        if(copy($sourcePath, $targetPath)) {
278
+        if (copy($sourcePath, $targetPath)) {
279 279
             return;
280 280
         }
281 281
         
@@ -302,11 +302,11 @@  discard block
 block discarded – undo
302 302
     */
303 303
     public static function deleteFile(string $filePath) : void
304 304
     {
305
-        if(!file_exists($filePath)) {
305
+        if (!file_exists($filePath)) {
306 306
             return;
307 307
         }
308 308
         
309
-        if(unlink($filePath)) {
309
+        if (unlink($filePath)) {
310 310
             return;
311 311
         }
312 312
         
@@ -330,10 +330,10 @@  discard block
 block discarded – undo
330 330
     * @return \parseCSV
331 331
     * @todo Move this to the CSV helper.
332 332
     */
333
-    public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : \parseCSV
333
+    public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : \parseCSV
334 334
     {
335
-        if($delimiter==='') { $delimiter = ';'; }
336
-        if($enclosure==='') { $enclosure = '"'; }
335
+        if ($delimiter === '') { $delimiter = ';'; }
336
+        if ($enclosure === '') { $enclosure = '"'; }
337 337
         
338 338
         $parser = new \parseCSV(null, null, null, array());
339 339
 
@@ -361,11 +361,11 @@  discard block
 block discarded – undo
361 361
     * @see parseCSVFile()
362 362
     * @see FileHelper::ERROR_PARSING_CSV
363 363
     */
364
-    public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array
364
+    public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array
365 365
     {
366 366
         $parser = self::createCSVParser($delimiter, $enclosure, $escape, $heading);
367 367
         $result = $parser->parse_string(/** @scrutinizer ignore-type */ $csv);
368
-        if(is_array($result)) {
368
+        if (is_array($result)) {
369 369
             return $result;
370 370
         }
371 371
         
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
      * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
394 394
      * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS
395 395
      */
396
-    public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array
396
+    public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array
397 397
     {
398 398
         $content = self::readContents($filePath);
399 399
 
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
     public static function detectMimeType(string $fileName) : ?string
411 411
     {
412 412
         $ext = self::getExtension($fileName);
413
-        if(empty($ext)) {
413
+        if (empty($ext)) {
414 414
             return null;
415 415
         }
416 416
 
@@ -434,11 +434,11 @@  discard block
 block discarded – undo
434 434
      * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
435 435
      * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE
436 436
      */
437
-    public static function sendFile(string $filePath, $fileName = null, bool $asAttachment=true, bool $exit=true)
437
+    public static function sendFile(string $filePath, $fileName = null, bool $asAttachment = true, bool $exit = true)
438 438
     {
439 439
         self::requireFileExists($filePath);
440 440
         
441
-        if(empty($fileName)) {
441
+        if (empty($fileName)) {
442 442
             $fileName = basename($filePath);
443 443
         }
444 444
 
@@ -456,10 +456,10 @@  discard block
 block discarded – undo
456 456
         
457 457
         header("Cache-Control: public", true);
458 458
         header("Content-Description: File Transfer", true);
459
-        header("Content-Type: " . $mime, true);
459
+        header("Content-Type: ".$mime, true);
460 460
 
461 461
         $disposition = 'inline';
462
-        if($asAttachment) {
462
+        if ($asAttachment) {
463 463
             $disposition = 'attachment';
464 464
         }
465 465
         
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
         
472 472
         readfile($filePath);
473 473
         
474
-        if($exit) 
474
+        if ($exit) 
475 475
         {
476 476
             exit;
477 477
         }
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
      */
491 491
     public static function downloadFile($url)
492 492
     {
493
-        if(!function_exists('curl_init')) 
493
+        if (!function_exists('curl_init')) 
494 494
         {
495 495
             throw new FileHelper_Exception(
496 496
                 'The cURL extension is not installed.',
@@ -500,7 +500,7 @@  discard block
 block discarded – undo
500 500
         }
501 501
 
502 502
         $ch = curl_init();
503
-        if($ch === false) 
503
+        if ($ch === false) 
504 504
         {
505 505
             throw new FileHelper_Exception(
506 506
                 'Could not initialize a new cURL instance.',
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
         
522 522
         $output = curl_exec($ch);
523 523
 
524
-        if($output === false) {
524
+        if ($output === false) {
525 525
             throw new FileHelper_Exception(
526 526
                 'Unable to open URL',
527 527
                 sprintf(
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
 
536 536
         curl_close($ch);
537 537
 
538
-        if(is_string($output)) 
538
+        if (is_string($output)) 
539 539
         {
540 540
             return $output;
541 541
         }
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
     */
558 558
     public static function isPHPFile($pathOrDirIterator)
559 559
     {
560
-    	if(self::getExtension($pathOrDirIterator) == 'php') {
560
+    	if (self::getExtension($pathOrDirIterator) == 'php') {
561 561
     		return true;
562 562
     	}
563 563
     	
@@ -574,14 +574,14 @@  discard block
 block discarded – undo
574 574
     */
575 575
     public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string
576 576
     {
577
-        if($pathOrDirIterator instanceof \DirectoryIterator) {
577
+        if ($pathOrDirIterator instanceof \DirectoryIterator) {
578 578
             $filename = $pathOrDirIterator->getFilename();
579 579
         } else {
580 580
             $filename = basename($pathOrDirIterator);
581 581
         }
582 582
          
583 583
         $ext = pathinfo($filename, PATHINFO_EXTENSION);
584
-        if($lowercase) {
584
+        if ($lowercase) {
585 585
         	$ext = mb_strtolower($ext);
586 586
         }
587 587
         
@@ -603,13 +603,13 @@  discard block
 block discarded – undo
603 603
     public static function getFilename($pathOrDirIterator, $extension = true)
604 604
     {
605 605
         $path = $pathOrDirIterator;
606
-    	if($pathOrDirIterator instanceof \DirectoryIterator) {
606
+    	if ($pathOrDirIterator instanceof \DirectoryIterator) {
607 607
     		$path = $pathOrDirIterator->getFilename();
608 608
     	}
609 609
     	
610 610
     	$path = self::normalizePath($path);
611 611
     	
612
-    	if(!$extension) {
612
+    	if (!$extension) {
613 613
     	    return pathinfo($path, PATHINFO_FILENAME);
614 614
     	}
615 615
     	
@@ -627,12 +627,12 @@  discard block
 block discarded – undo
627 627
     * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE
628 628
     * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE
629 629
     */ 
630
-    public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null)
630
+    public static function parseJSONFile(string $file, $targetEncoding = null, $sourceEncoding = null)
631 631
     {
632 632
         self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE);
633 633
         
634 634
         $content = file_get_contents($file);
635
-        if(!$content) {
635
+        if (!$content) {
636 636
             throw new FileHelper_Exception(
637 637
                 'Cannot get file contents',
638 638
                 sprintf(
@@ -643,12 +643,12 @@  discard block
 block discarded – undo
643 643
             );
644 644
         }
645 645
         
646
-        if(isset($targetEncoding)) {
646
+        if (isset($targetEncoding)) {
647 647
             $content = mb_convert_encoding($content, $targetEncoding, $sourceEncoding);
648 648
         }
649 649
         
650 650
         $json = json_decode($content, true);
651
-        if($json === false || $json === NULL) {
651
+        if ($json === false || $json === NULL) {
652 652
             throw new FileHelper_Exception(
653 653
                 'Cannot decode json data',
654 654
                 sprintf(
@@ -688,13 +688,13 @@  discard block
 block discarded – undo
688 688
         
689 689
         $name = str_replace(array_keys($replaces), array_values($replaces), $name);
690 690
         
691
-        while(strstr($name, '  ')) {
691
+        while (strstr($name, '  ')) {
692 692
             $name = str_replace('  ', ' ', $name);
693 693
         }
694 694
 
695 695
         $name = str_replace(array_keys($replaces), array_values($replaces), $name);
696 696
         
697
-        while(strstr($name, '..')) {
697
+        while (strstr($name, '..')) {
698 698
             $name = str_replace('..', '.', $name);
699 699
         }
700 700
         
@@ -724,7 +724,7 @@  discard block
 block discarded – undo
724 724
     * 
725 725
     * @todo Convert this to use the file finder.
726 726
     */
727
-    public static function findHTMLFiles(string $targetFolder, array $options=array()) : array
727
+    public static function findHTMLFiles(string $targetFolder, array $options = array()) : array
728 728
     {
729 729
         return self::findFiles($targetFolder, array('html'), $options);
730 730
     }
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
     * 
740 740
     * @todo Convert this to use the file finder.
741 741
     */
742
-    public static function findPHPFiles(string $targetFolder, array $options=array()) : array
742
+    public static function findPHPFiles(string $targetFolder, array $options = array()) : array
743 743
     {
744 744
         return self::findFiles($targetFolder, array('php'), $options);
745 745
     }
@@ -755,39 +755,39 @@  discard block
 block discarded – undo
755 755
     * @deprecated Will be replaced by the file finder in the future.
756 756
     * @see FileHelper::createFileFinder()
757 757
     */
758
-    public static function findFiles(string $targetFolder, array $extensions=array(), array $options=array(), array $files=array()) : array
758
+    public static function findFiles(string $targetFolder, array $extensions = array(), array $options = array(), array $files = array()) : array
759 759
     {
760
-        if(!isset($options['strip-extension'])) {
760
+        if (!isset($options['strip-extension'])) {
761 761
             $options['strip-extension'] = false;
762 762
         }
763 763
         
764
-        if(!isset($options['absolute-path'])) {
764
+        if (!isset($options['absolute-path'])) {
765 765
             $options['absolute-path'] = false;
766 766
         } 
767 767
         
768
-        if(!isset($options['relative-path'])) {
768
+        if (!isset($options['relative-path'])) {
769 769
             $options['relative-path'] = false;
770 770
         }
771 771
         
772
-        if(!isset($options['recursive'])) {
772
+        if (!isset($options['recursive'])) {
773 773
             $options['recursive'] = false;
774 774
         }
775 775
         
776
-        if($options['relative-path']) {
776
+        if ($options['relative-path']) {
777 777
             $options['absolute-path'] = true;
778 778
         }
779 779
         
780
-        if(!isset($options['__root'])) {
780
+        if (!isset($options['__root'])) {
781 781
             $options['__root'] = self::normalizePath($targetFolder);
782 782
         }
783 783
         
784 784
         $checkExtensions = false;
785
-        if(!empty($extensions)) {
785
+        if (!empty($extensions)) {
786 786
             $checkExtensions = true;
787 787
             $extensions = array_map('strtolower', $extensions);
788 788
         }
789 789
         
790
-        if(!is_dir($targetFolder)) 
790
+        if (!is_dir($targetFolder)) 
791 791
         {
792 792
             throw new FileHelper_Exception(
793 793
                 'Target folder does not exist',
@@ -800,32 +800,32 @@  discard block
 block discarded – undo
800 800
         }
801 801
         
802 802
         $d = new \DirectoryIterator($targetFolder);
803
-        foreach($d as $item) {
804
-            if($item->isDot()) {
803
+        foreach ($d as $item) {
804
+            if ($item->isDot()) {
805 805
                 continue;
806 806
             }
807 807
             
808
-            if($item->isDir()) {
809
-                if($options['recursive']) {
808
+            if ($item->isDir()) {
809
+                if ($options['recursive']) {
810 810
                     $files = self::findFiles($item->getPathname(), $extensions, $options, $files);
811 811
                 }
812 812
                 continue;
813 813
             }
814 814
             
815
-            if($checkExtensions && !in_array(self::getExtension($item, true), $extensions)) {
815
+            if ($checkExtensions && !in_array(self::getExtension($item, true), $extensions)) {
816 816
                 continue;
817 817
             }
818 818
             
819 819
             $filename = $item->getFilename();
820
-            if($options['strip-extension']) {
820
+            if ($options['strip-extension']) {
821 821
                 $filename = self::removeExtension($filename);
822 822
             }
823 823
             
824
-            if($options['absolute-path']) {
824
+            if ($options['absolute-path']) {
825 825
                 $filename = self::normalizePath($targetFolder.'/'.$filename);
826 826
             }
827 827
             
828
-            if($options['relative-path']) {
828
+            if ($options['relative-path']) {
829 829
                 $filename = ltrim(str_replace($options['__root'], '', $filename), '/');
830 830
             }
831 831
             
@@ -873,9 +873,9 @@  discard block
 block discarded – undo
873 873
         fclose($fp);
874 874
 
875 875
         $boms = self::getUTFBOMs();
876
-        foreach($boms as $bom => $value) {
876
+        foreach ($boms as $bom => $value) {
877 877
             $length = mb_strlen($value);
878
-            if(mb_substr($text, 0, $length) == $value) {
878
+            if (mb_substr($text, 0, $length) == $value) {
879 879
                 return $bom;
880 880
             }
881 881
         }
@@ -894,13 +894,13 @@  discard block
 block discarded – undo
894 894
     */
895 895
     public static function getUTFBOMs()
896 896
     {
897
-        if(!isset(self::$utfBoms)) {
897
+        if (!isset(self::$utfBoms)) {
898 898
             self::$utfBoms = array(
899
-                'UTF32-BE' => chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF),
900
-                'UTF32-LE' => chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00),
901
-                'UTF16-BE' => chr(0xFE) . chr(0xFF),
902
-                'UTF16-LE' => chr(0xFF) . chr(0xFE),
903
-                'UTF8' => chr(0xEF) . chr(0xBB) . chr(0xBF)
899
+                'UTF32-BE' => chr(0x00).chr(0x00).chr(0xFE).chr(0xFF),
900
+                'UTF32-LE' => chr(0xFF).chr(0xFE).chr(0x00).chr(0x00),
901
+                'UTF16-BE' => chr(0xFE).chr(0xFF),
902
+                'UTF16-LE' => chr(0xFF).chr(0xFE),
903
+                'UTF8' => chr(0xEF).chr(0xBB).chr(0xBF)
904 904
             );
905 905
         }
906 906
         
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
         $encodings = self::getKnownUnicodeEncodings();
922 922
 
923 923
         $keep = array();
924
-        foreach($encodings as $string) 
924
+        foreach ($encodings as $string) 
925 925
         {
926 926
             $withHyphen = str_replace('UTF', 'UTF-', $string);
927 927
             
@@ -955,15 +955,15 @@  discard block
 block discarded – undo
955 955
         return str_replace(array('\\', '//'), array('/', '/'), $path);
956 956
     }
957 957
     
958
-    public static function saveAsJSON($data, $file, $pretty=false)
958
+    public static function saveAsJSON($data, $file, $pretty = false)
959 959
     {
960 960
         $options = null;
961
-        if($pretty) {
961
+        if ($pretty) {
962 962
             $options = JSON_PRETTY_PRINT;
963 963
         }
964 964
         
965 965
         $json = json_encode($data, $options);
966
-        if($json===false) 
966
+        if ($json === false) 
967 967
         {
968 968
             $errorCode = json_last_error();
969 969
             throw new FileHelper_Exception(
@@ -973,7 +973,7 @@  discard block
 block discarded – undo
973 973
             ); 
974 974
         }
975 975
         
976
-        if(!file_put_contents($file, $json)) {
976
+        if (!file_put_contents($file, $json)) {
977 977
             throw new FileHelper_Exception(
978 978
                 sprintf('Could not write the JSON file [%s] to disk.', basename($file)),
979 979
                 sprintf('Full path: [%s].', $file),
@@ -994,12 +994,12 @@  discard block
 block discarded – undo
994 994
     * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
995 995
     * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
996 996
     */
997
-    public static function saveFile(string $filePath, string $content='') : void
997
+    public static function saveFile(string $filePath, string $content = '') : void
998 998
     {
999 999
         // target file already exists
1000
-        if(file_exists($filePath))
1000
+        if (file_exists($filePath))
1001 1001
         {
1002
-            if(!is_writable($filePath))
1002
+            if (!is_writable($filePath))
1003 1003
             {
1004 1004
                 throw new FileHelper_Exception(
1005 1005
                     sprintf('Cannot save file: target file [%s] exists, but is not writable.', basename($filePath)),
@@ -1019,7 +1019,7 @@  discard block
 block discarded – undo
1019 1019
             // create the folder as needed
1020 1020
             self::createFolder($targetFolder);
1021 1021
             
1022
-            if(!is_writable($targetFolder)) 
1022
+            if (!is_writable($targetFolder)) 
1023 1023
             {
1024 1024
                 throw new FileHelper_Exception(
1025 1025
                     sprintf('Cannot save file: target folder [%s] is not writable.', basename($targetFolder)),
@@ -1032,7 +1032,7 @@  discard block
 block discarded – undo
1032 1032
             }
1033 1033
         }
1034 1034
         
1035
-        if(file_put_contents($filePath, $content) !== false) {
1035
+        if (file_put_contents($filePath, $content) !== false) {
1036 1036
             return;
1037 1037
         }
1038 1038
         
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
     {
1069 1069
         static $checked = array();
1070 1070
         
1071
-        if(isset($checked[$command])) {
1071
+        if (isset($checked[$command])) {
1072 1072
             return $checked[$command];
1073 1073
         }
1074 1074
         
@@ -1081,7 +1081,7 @@  discard block
 block discarded – undo
1081 1081
         
1082 1082
         $os = strtolower(PHP_OS_FAMILY);
1083 1083
         
1084
-        if(!isset($osCommands[$os])) 
1084
+        if (!isset($osCommands[$os])) 
1085 1085
         {
1086 1086
             throw new FileHelper_Exception(
1087 1087
                 'Unsupported OS for CLI commands',
@@ -1107,7 +1107,7 @@  discard block
 block discarded – undo
1107 1107
             $pipes
1108 1108
         );
1109 1109
         
1110
-        if($process === false) {
1110
+        if ($process === false) {
1111 1111
             $checked[$command] = false;
1112 1112
             return false;
1113 1113
         }
@@ -1138,7 +1138,7 @@  discard block
 block discarded – undo
1138 1138
     */
1139 1139
     public static function checkPHPFileSyntax($path)
1140 1140
     {
1141
-        if(!self::canMakePHPCalls()) {
1141
+        if (!self::canMakePHPCalls()) {
1142 1142
             return true;
1143 1143
         }
1144 1144
         
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
         // when the validation is successful, the first entry
1150 1150
         // in the array contains the success message. When it
1151 1151
         // is invalid, the first entry is always empty.
1152
-        if(!empty($output[0])) {
1152
+        if (!empty($output[0])) {
1153 1153
             return true;
1154 1154
         }
1155 1155
         
@@ -1170,7 +1170,7 @@  discard block
 block discarded – undo
1170 1170
     public static function getModifiedDate($path)
1171 1171
     {
1172 1172
         $time = filemtime($path);
1173
-        if($time !== false) {
1173
+        if ($time !== false) {
1174 1174
             $date = new \DateTime();
1175 1175
             $date->setTimestamp($time);
1176 1176
             return $date;
@@ -1197,7 +1197,7 @@  discard block
 block discarded – undo
1197 1197
     */
1198 1198
     public static function getSubfolders($targetFolder, $options = array())
1199 1199
     {
1200
-        if(!is_dir($targetFolder)) 
1200
+        if (!is_dir($targetFolder)) 
1201 1201
         {
1202 1202
             throw new FileHelper_Exception(
1203 1203
                 'Target folder does not exist',
@@ -1221,29 +1221,29 @@  discard block
 block discarded – undo
1221 1221
         
1222 1222
         $d = new \DirectoryIterator($targetFolder);
1223 1223
         
1224
-        foreach($d as $item) 
1224
+        foreach ($d as $item) 
1225 1225
         {
1226
-            if($item->isDir() && !$item->isDot()) 
1226
+            if ($item->isDir() && !$item->isDot()) 
1227 1227
             {
1228 1228
                 $name = $item->getFilename();
1229 1229
                 
1230
-                if(!$options['absolute-path']) {
1230
+                if (!$options['absolute-path']) {
1231 1231
                     $result[] = $name;
1232 1232
                 } else {
1233 1233
                     $result[] = $targetFolder.'/'.$name;
1234 1234
                 }
1235 1235
                 
1236
-                if(!$options['recursive']) 
1236
+                if (!$options['recursive']) 
1237 1237
                 {
1238 1238
                     continue;
1239 1239
                 }
1240 1240
                 
1241 1241
                 $subs = self::getSubfolders($targetFolder.'/'.$name, $options);
1242
-                foreach($subs as $sub) 
1242
+                foreach ($subs as $sub) 
1243 1243
                 {
1244 1244
                     $relative = $name.'/'.$sub;
1245 1245
                     
1246
-                    if(!$options['absolute-path']) {
1246
+                    if (!$options['absolute-path']) {
1247 1247
                         $result[] = $relative;
1248 1248
                     } else {
1249 1249
                         $result[] = $targetFolder.'/'.$relative;
@@ -1311,7 +1311,7 @@  discard block
 block discarded – undo
1311 1311
     * @param int $depth The folder depth to reduce the path to
1312 1312
     * @return string
1313 1313
     */
1314
-    public static function relativizePathByDepth(string $path, int $depth=2) : string
1314
+    public static function relativizePathByDepth(string $path, int $depth = 2) : string
1315 1315
     {
1316 1316
         $path = self::normalizePath($path);
1317 1317
         
@@ -1319,17 +1319,17 @@  discard block
 block discarded – undo
1319 1319
         $tokens = array_filter($tokens); // remove empty entries (trailing slash for example)
1320 1320
         $tokens = array_values($tokens); // re-index keys
1321 1321
         
1322
-        if(empty($tokens)) {
1322
+        if (empty($tokens)) {
1323 1323
             return '';
1324 1324
         }
1325 1325
         
1326 1326
         // remove the drive if present
1327
-        if(strstr($tokens[0], ':')) {
1327
+        if (strstr($tokens[0], ':')) {
1328 1328
             array_shift($tokens);
1329 1329
         }
1330 1330
         
1331 1331
         // path was only the drive
1332
-        if(count($tokens) == 0) {
1332
+        if (count($tokens) == 0) {
1333 1333
             return '';
1334 1334
         }
1335 1335
 
@@ -1338,8 +1338,8 @@  discard block
 block discarded – undo
1338 1338
         
1339 1339
         // reduce the path to the specified depth
1340 1340
         $length = count($tokens);
1341
-        if($length > $depth) {
1342
-            $tokens = array_slice($tokens, $length-$depth);
1341
+        if ($length > $depth) {
1342
+            $tokens = array_slice($tokens, $length - $depth);
1343 1343
         }
1344 1344
 
1345 1345
         // append the last element again
@@ -1387,14 +1387,14 @@  discard block
 block discarded – undo
1387 1387
     * 
1388 1388
     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1389 1389
     */
1390
-    public static function requireFileExists(string $path, $errorCode=null) : string
1390
+    public static function requireFileExists(string $path, $errorCode = null) : string
1391 1391
     {
1392 1392
         $result = realpath($path);
1393
-        if($result !== false) {
1393
+        if ($result !== false) {
1394 1394
             return $result;
1395 1395
         }
1396 1396
         
1397
-        if($errorCode === null) {
1397
+        if ($errorCode === null) {
1398 1398
             $errorCode = self::ERROR_FILE_DOES_NOT_EXIST;
1399 1399
         }
1400 1400
         
@@ -1423,15 +1423,15 @@  discard block
 block discarded – undo
1423 1423
         
1424 1424
         $file = new \SplFileObject($path);
1425 1425
         
1426
-        if($file->eof()) {
1426
+        if ($file->eof()) {
1427 1427
             return '';
1428 1428
         }
1429 1429
         
1430
-        $targetLine = $lineNumber-1;
1430
+        $targetLine = $lineNumber - 1;
1431 1431
         
1432 1432
         $file->seek($targetLine);
1433 1433
         
1434
-        if($file->key() !== $targetLine) {
1434
+        if ($file->key() !== $targetLine) {
1435 1435
              return null;
1436 1436
         }
1437 1437
         
@@ -1457,7 +1457,7 @@  discard block
 block discarded – undo
1457 1457
         $number = $spl->key();
1458 1458
         
1459 1459
         // if seeking to the end the cursor is still at 0, there are no lines. 
1460
-        if($number === 0) 
1460
+        if ($number === 0) 
1461 1461
         {
1462 1462
             // since it's a very small file, to get reliable results,
1463 1463
             // we read its contents and use that to determine what
@@ -1465,13 +1465,13 @@  discard block
 block discarded – undo
1465 1465
             // that this is not pactical to solve with the SplFileObject.
1466 1466
             $content = file_get_contents($path);
1467 1467
             
1468
-            if(empty($content)) {
1468
+            if (empty($content)) {
1469 1469
                 return 0;
1470 1470
             }
1471 1471
         }
1472 1472
         
1473 1473
         // return the line number we were able to reach + 1 (key is zero-based)
1474
-        return $number+1;
1474
+        return $number + 1;
1475 1475
     }
1476 1476
     
1477 1477
    /**
@@ -1518,13 +1518,13 @@  discard block
 block discarded – undo
1518 1518
     * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES
1519 1519
     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1520 1520
     */
1521
-    public static function readLines(string $filePath, int $amount=0) : array
1521
+    public static function readLines(string $filePath, int $amount = 0) : array
1522 1522
     {
1523 1523
         self::requireFileExists($filePath);
1524 1524
         
1525 1525
         $fn = fopen($filePath, "r");
1526 1526
         
1527
-        if($fn === false) 
1527
+        if ($fn === false) 
1528 1528
         {
1529 1529
             throw new FileHelper_Exception(
1530 1530
                 'Could not open file for reading.',
@@ -1540,25 +1540,25 @@  discard block
 block discarded – undo
1540 1540
         $counter = 0;
1541 1541
         $first = true;
1542 1542
         
1543
-        while(!feof($fn)) 
1543
+        while (!feof($fn)) 
1544 1544
         {
1545 1545
             $counter++;
1546 1546
             
1547 1547
             $line = fgets($fn);
1548 1548
             
1549 1549
             // can happen with zero length files
1550
-            if($line === false) {
1550
+            if ($line === false) {
1551 1551
                 continue;
1552 1552
             }
1553 1553
             
1554 1554
             // the first line may contain a unicode BOM marker.
1555
-            if($first) {
1555
+            if ($first) {
1556 1556
                 $line = ConvertHelper::stripUTFBom($line);
1557 1557
             }
1558 1558
             
1559 1559
             $result[] = $line;
1560 1560
             
1561
-            if($amount > 0 && $counter == $amount) {
1561
+            if ($amount > 0 && $counter == $amount) {
1562 1562
                 break;
1563 1563
             }
1564 1564
         }
@@ -1584,7 +1584,7 @@  discard block
 block discarded – undo
1584 1584
         
1585 1585
         $result = file_get_contents($filePath);
1586 1586
         
1587
-        if($result !== false) {
1587
+        if ($result !== false) {
1588 1588
             return $result;
1589 1589
         }
1590 1590
         
Please login to merge, or discard this patch.