Passed
Push — master ( c49a71...1dce7e )
by Sebastian
04:29
created
src/FileHelper/FileFinder.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace AppUtils;
6 6
 
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
         return $this;
98 98
     }
99 99
     
100
-    protected function getOption($name, $default=null)
100
+    protected function getOption($name, $default = null)
101 101
     {
102
-        if(isset($this->options[$name])) {
102
+        if (isset($this->options[$name])) {
103 103
             return $this->options[$name];
104 104
         }
105 105
         
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
     
109 109
     public function getAll() : array
110 110
     {
111
-        if(!isset($this->found)) {
111
+        if (!isset($this->found)) {
112 112
             $this->find($this->path, true);
113 113
         }
114 114
         
@@ -133,25 +133,25 @@  discard block
 block discarded – undo
133 133
     
134 134
     protected $found;
135 135
     
136
-    protected function find($path, $isRoot=false)
136
+    protected function find($path, $isRoot = false)
137 137
     {
138
-        if($isRoot) {
138
+        if ($isRoot) {
139 139
             $this->found = array();
140 140
         }
141 141
         
142 142
         $d = new \DirectoryIterator($path);
143
-        foreach($d as $item)
143
+        foreach ($d as $item)
144 144
         {
145
-            if($item->isDir())
145
+            if ($item->isDir())
146 146
             {
147
-                if($this->getOption('recursive') === true && !$item->isDot()) {
147
+                if ($this->getOption('recursive') === true && !$item->isDot()) {
148 148
                     $this->find($item->getPathname());
149 149
                 }
150 150
             }
151 151
             else
152 152
             {
153 153
                 $file = $this->filterFile($item->getPathname());
154
-                if($file) {
154
+                if ($file) {
155 155
                     $this->found[] = $file;
156 156
                 }
157 157
             }
@@ -167,20 +167,20 @@  discard block
 block discarded – undo
167 167
         $include = $this->getOption('include-extensions');
168 168
         $exclude = $this->getOption('exclude-extensions');
169 169
         
170
-        if(!empty($include))
170
+        if (!empty($include))
171 171
         {
172
-            if(!in_array($info['extension'], $include)) {
172
+            if (!in_array($info['extension'], $include)) {
173 173
                 return false;
174 174
             }
175 175
         }
176
-        else if(!empty($exclude))
176
+        else if (!empty($exclude))
177 177
         {
178
-            if(in_array($info['extension'], $exclude)) {
178
+            if (in_array($info['extension'], $exclude)) {
179 179
                 return false;
180 180
             }
181 181
         }
182 182
         
183
-        switch($this->getOption('pathmode'))
183
+        switch ($this->getOption('pathmode'))
184 184
         {
185 185
             case self::PATH_MODE_STRIP:
186 186
                 $path = basename($path);
@@ -196,13 +196,13 @@  discard block
 block discarded – undo
196 196
                 break;
197 197
         }
198 198
         
199
-        if($this->getOption('strip-extensions') === true)
199
+        if ($this->getOption('strip-extensions') === true)
200 200
         {
201 201
             $path = str_replace('.'.$info['extension'], '', $path);
202 202
         }
203 203
         
204 204
         $replace = $this->getOption('slash-replacement');
205
-        if(!empty($replace)) {
205
+        if (!empty($replace)) {
206 206
             $path = str_replace('/', $replace, $path);
207 207
         }
208 208
         
Please login to merge, or discard this patch.
src/FileHelper/MimeTypes.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -221,7 +221,7 @@
 block discarded – undo
221 221
      */
222 222
     public static function getMime($extension)
223 223
     {
224
-        if(isset(self::$mimeTypes[$extension])) {
224
+        if (isset(self::$mimeTypes[$extension])) {
225 225
             return self::$mimeTypes[$extension];
226 226
         }
227 227
 
Please login to merge, or discard this patch.
src/FileHelper/PHPClassInfo/Class.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
     {
106 106
         $name = $this->getName();
107 107
         
108
-        if($this->info->hasNamespace()) {
108
+        if ($this->info->hasNamespace()) {
109 109
             $name = $this->info->getNamespace().'\\'.$this->name;
110 110
         }
111 111
         
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
         $parts[] = 'class';
161 161
         $parts[] = $this->getName();
162 162
         
163
-        if(!empty($this->extends)) {
163
+        if (!empty($this->extends)) {
164 164
             $parts[] = 'extends';
165 165
             $parts[] = $this->extends;
166 166
         }
167 167
         
168
-        if(!empty($this->implements)) {
168
+        if (!empty($this->implements)) {
169 169
             $parts[] = 'implements';
170 170
             $parts[] = implode(', ', $this->implements);
171 171
         }
@@ -184,9 +184,9 @@  discard block
 block discarded – undo
184 184
     
185 185
     protected function analyzeCode()
186 186
     {
187
-        if($this->keyword == 'abstract') {
187
+        if ($this->keyword == 'abstract') {
188 188
             $this->abstract = true;
189
-        } else if($this->keyword == 'final') {
189
+        } else if ($this->keyword == 'final') {
190 190
             $this->final = true;
191 191
         }
192 192
         
@@ -203,16 +203,16 @@  discard block
 block discarded – undo
203 203
         
204 204
         $tokenName = 'none';
205 205
         
206
-        foreach($parts as $part)
206
+        foreach ($parts as $part)
207 207
         {
208 208
             $part = str_replace(',', '', $part);
209 209
             $part = trim($part);
210
-            if(empty($part)) {
210
+            if (empty($part)) {
211 211
                 continue;
212 212
             }
213 213
             
214 214
             $name = strtolower($part);
215
-            if($name == 'extends' || $name == 'implements') {
215
+            if ($name == 'extends' || $name == 'implements') {
216 216
                 $tokenName = $name;
217 217
                 continue;
218 218
             }
@@ -222,13 +222,13 @@  discard block
 block discarded – undo
222 222
         
223 223
         $this->implements = $tokens['implements'];
224 224
         
225
-        if(!empty($this->implements)) {
225
+        if (!empty($this->implements)) {
226 226
             usort($this->implements, function(string $a, string $b) {
227 227
                 return strnatcasecmp($a, $b);
228 228
             });
229 229
         }
230 230
         
231
-        if(!empty($tokens['extends'])) {
231
+        if (!empty($tokens['extends'])) {
232 232
             $this->extends = $tokens['extends'][0];
233 233
         }
234 234
     }
Please login to merge, or discard this patch.
src/ImageHelper/Size.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,23 +18,23 @@  discard block
 block discarded – undo
18 18
     
19 19
     public function __construct(array $size)
20 20
     {
21
-        if(!isset($size['width'])) {
21
+        if (!isset($size['width'])) {
22 22
             $size['width'] = $size[0];
23 23
         }
24 24
         
25
-        if(!isset($size['height'])) {
25
+        if (!isset($size['height'])) {
26 26
             $size['height'] = $size[1];
27 27
         }
28 28
         
29
-        if(!isset($size[0])) {
29
+        if (!isset($size[0])) {
30 30
             $size[0] = $size['width'];
31 31
         }
32 32
         
33
-        if(!isset($size[1])) {
33
+        if (!isset($size[1])) {
34 34
             $size[1] = $size['height'];
35 35
         }
36 36
         
37
-        if(!isset($size['channels'])) {
37
+        if (!isset($size['channels'])) {
38 38
             $size['channels'] = 1;
39 39
         }
40 40
         
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     
69 69
     public function offsetGet($offset)
70 70
     {
71
-        if(isset($this->size[$offset])) {
71
+        if (isset($this->size[$offset])) {
72 72
             return $this->size[$offset];
73 73
         }
74 74
         
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
     
78 78
     public function offsetSet($offset, $value)
79 79
     {
80
-        if(is_null($offset)) {
80
+        if (is_null($offset)) {
81 81
             $this->size[] = $value;
82 82
         } else {
83 83
             $this->size[$offset] = $value;
Please login to merge, or discard this patch.
src/FileHelper.php 1 patch
Spacing   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         
91 91
         $contents = file_get_contents($file);
92 92
         
93
-        if($contents === false) 
93
+        if ($contents === false) 
94 94
         {
95 95
             throw new FileHelper_Exception(
96 96
                 'Cannot load serialized content from file.',
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
         
105 105
         $result = @unserialize($contents);
106 106
         
107
-        if($result !== false) {
107
+        if ($result !== false) {
108 108
             return $result;
109 109
         }
110 110
         
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
     
121 121
     public static function deleteTree($rootFolder)
122 122
     {
123
-        if(!file_exists($rootFolder)) {
123
+        if (!file_exists($rootFolder)) {
124 124
             return true;
125 125
         }
126 126
         
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
     */
162 162
     public static function createFolder($path)
163 163
     {
164
-        if(is_dir($path) || mkdir($path, 0777, true)) {
164
+        if (is_dir($path) || mkdir($path, 0777, true)) {
165 165
             return;
166 166
         }
167 167
         
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
 
197 197
             if ($item->isDir()) 
198 198
             {
199
-                FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target . '/' . $baseName);
199
+                FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target.'/'.$baseName);
200 200
             } 
201
-            else if($item->isFile()) 
201
+            else if ($item->isFile()) 
202 202
             {
203
-                self::copyFile($itemPath, $target . '/' . $baseName);
203
+                self::copyFile($itemPath, $target.'/'.$baseName);
204 204
             }
205 205
         }
206 206
     }
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
     {
226 226
         self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND);
227 227
         
228
-        if(!is_readable($sourcePath))
228
+        if (!is_readable($sourcePath))
229 229
         {
230 230
             throw new FileHelper_Exception(
231 231
                 sprintf('Source file [%s] to copy is not readable.', basename($sourcePath)),
@@ -239,11 +239,11 @@  discard block
 block discarded – undo
239 239
         
240 240
         $targetFolder = dirname($targetPath);
241 241
         
242
-        if(!file_exists($targetFolder))
242
+        if (!file_exists($targetFolder))
243 243
         {
244 244
             self::createFolder($targetFolder);
245 245
         }
246
-        else if(!is_writable($targetFolder)) 
246
+        else if (!is_writable($targetFolder)) 
247 247
         {
248 248
             throw new FileHelper_Exception(
249 249
                 sprintf('Target folder [%s] is not writable.', basename($targetFolder)),
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
             );
256 256
         }
257 257
         
258
-        if(copy($sourcePath, $targetPath)) {
258
+        if (copy($sourcePath, $targetPath)) {
259 259
             return;
260 260
         }
261 261
         
@@ -282,11 +282,11 @@  discard block
 block discarded – undo
282 282
     */
283 283
     public static function deleteFile(string $filePath) : void
284 284
     {
285
-        if(!file_exists($filePath)) {
285
+        if (!file_exists($filePath)) {
286 286
             return;
287 287
         }
288 288
         
289
-        if(unlink($filePath)) {
289
+        if (unlink($filePath)) {
290 290
             return;
291 291
         }
292 292
         
@@ -308,11 +308,11 @@  discard block
 block discarded – undo
308 308
     * @param string $heading
309 309
     * @return \parseCSV
310 310
     */
311
-    public static function createCSVParser($delimiter = ';', $enclosure = '"', $escape = '\\', $heading=false)
311
+    public static function createCSVParser($delimiter = ';', $enclosure = '"', $escape = '\\', $heading = false)
312 312
     {
313
-        if($delimiter===null) { $delimiter = ';'; }
314
-        if($enclosure===null) { $enclosure = '"'; }
315
-        if($escape===null) { $escape = '\\'; }
313
+        if ($delimiter === null) { $delimiter = ';'; }
314
+        if ($enclosure === null) { $enclosure = '"'; }
315
+        if ($escape === null) { $escape = '\\'; }
316 316
         
317 317
         $parser = new \parseCSV(null, null, null, array());
318 318
 
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
      * @return array
335 335
      * @see parseCSVFile()
336 336
      */
337
-    public static function parseCSVString($csv, $delimiter = ';', $enclosure = '"', $escape = '\\', $heading=false)
337
+    public static function parseCSVString($csv, $delimiter = ';', $enclosure = '"', $escape = '\\', $heading = false)
338 338
     {
339 339
         $parser = self::createCSVParser($delimiter, $enclosure, $escape, $heading);
340 340
         return $parser->parse_string($csv);
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
      * @return array
352 352
      * @see parseCSVString()
353 353
      */
354
-    public static function parseCSVFile($filePath, $delimiter = ';', $enclosure = '"', $escape = '\\', $heading=false)
354
+    public static function parseCSVFile($filePath, $delimiter = ';', $enclosure = '"', $escape = '\\', $heading = false)
355 355
     {
356 356
         $content = file_get_contents($filePath);
357 357
         if (!$content) {
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
     public static function detectMimeType($fileName)
372 372
     {
373 373
         $ext = self::getExtension($fileName);
374
-        if(empty($ext)) {
374
+        if (empty($ext)) {
375 375
             return null;
376 376
         }
377 377
 
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
      * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
393 393
      * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE
394 394
      */
395
-    public static function sendFile($filePath, $fileName = null, $asAttachment=true)
395
+    public static function sendFile($filePath, $fileName = null, $asAttachment = true)
396 396
     {
397 397
         self::requireFileExists($filePath);
398 398
         
@@ -414,10 +414,10 @@  discard block
 block discarded – undo
414 414
         
415 415
         header("Cache-Control: public", true);
416 416
         header("Content-Description: File Transfer", true);
417
-        header("Content-Type: " . $mime, true);
417
+        header("Content-Type: ".$mime, true);
418 418
 
419 419
         $disposition = 'inline';
420
-        if($asAttachment) {
420
+        if ($asAttachment) {
421 421
             $disposition = 'attachment';
422 422
         }
423 423
         
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
     */
492 492
     public static function isPHPFile($pathOrDirIterator)
493 493
     {
494
-    	if(self::getExtension($pathOrDirIterator) == 'php') {
494
+    	if (self::getExtension($pathOrDirIterator) == 'php') {
495 495
     		return true;
496 496
     	}
497 497
     	
@@ -508,14 +508,14 @@  discard block
 block discarded – undo
508 508
     */
509 509
     public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string
510 510
     {
511
-        if($pathOrDirIterator instanceof \DirectoryIterator) {
511
+        if ($pathOrDirIterator instanceof \DirectoryIterator) {
512 512
             $filename = $pathOrDirIterator->getFilename();
513 513
         } else {
514 514
             $filename = basename($pathOrDirIterator);
515 515
         }
516 516
          
517 517
         $ext = pathinfo($filename, PATHINFO_EXTENSION);
518
-        if($lowercase) {
518
+        if ($lowercase) {
519 519
         	$ext = mb_strtolower($ext);
520 520
         }
521 521
         
@@ -537,13 +537,13 @@  discard block
 block discarded – undo
537 537
     public static function getFilename($pathOrDirIterator, $extension = true)
538 538
     {
539 539
         $path = $pathOrDirIterator;
540
-    	if($pathOrDirIterator instanceof \DirectoryIterator) {
540
+    	if ($pathOrDirIterator instanceof \DirectoryIterator) {
541 541
     		$path = $pathOrDirIterator->getFilename();
542 542
     	}
543 543
     	
544 544
     	$path = self::normalizePath($path);
545 545
     	
546
-    	if(!$extension) {
546
+    	if (!$extension) {
547 547
     	    return pathinfo($path, PATHINFO_FILENAME);
548 548
     	}
549 549
     	
@@ -561,12 +561,12 @@  discard block
 block discarded – undo
561 561
     * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE
562 562
     * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE
563 563
     */ 
564
-    public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null)
564
+    public static function parseJSONFile(string $file, $targetEncoding = null, $sourceEncoding = null)
565 565
     {
566 566
         self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE);
567 567
         
568 568
         $content = file_get_contents($file);
569
-        if(!$content) {
569
+        if (!$content) {
570 570
             throw new FileHelper_Exception(
571 571
                 'Cannot get file contents',
572 572
                 sprintf(
@@ -577,12 +577,12 @@  discard block
 block discarded – undo
577 577
             );
578 578
         }
579 579
         
580
-        if(isset($targetEncoding)) {
580
+        if (isset($targetEncoding)) {
581 581
             $content = mb_convert_encoding($content, $targetEncoding, $sourceEncoding);
582 582
         }
583 583
         
584 584
         $json = json_decode($content, true);
585
-        if($json === false || $json === NULL) {
585
+        if ($json === false || $json === NULL) {
586 586
             throw new FileHelper_Exception(
587 587
                 'Cannot decode json data',
588 588
                 sprintf(
@@ -622,13 +622,13 @@  discard block
 block discarded – undo
622 622
         
623 623
         $name = str_replace(array_keys($replaces), array_values($replaces), $name);
624 624
         
625
-        while(strstr($name, '  ')) {
625
+        while (strstr($name, '  ')) {
626 626
             $name = str_replace('  ', ' ', $name);
627 627
         }
628 628
 
629 629
         $name = str_replace(array_keys($replaces), array_values($replaces), $name);
630 630
         
631
-        while(strstr($name, '..')) {
631
+        while (strstr($name, '..')) {
632 632
             $name = str_replace('..', '.', $name);
633 633
         }
634 634
         
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
     * @return string[]
657 657
     * @see FileHelper::createFileFinder()
658 658
     */
659
-    public static function findHTMLFiles($targetFolder, $options=array())
659
+    public static function findHTMLFiles($targetFolder, $options = array())
660 660
     {
661 661
         return self::findFiles($targetFolder, array('html'), $options);
662 662
     }
@@ -669,44 +669,44 @@  discard block
 block discarded – undo
669 669
     * @return string[]
670 670
     * @see FileHelper::createFileFinder()
671 671
     */
672
-    public static function findPHPFiles($targetFolder, $options=array())
672
+    public static function findPHPFiles($targetFolder, $options = array())
673 673
     {
674 674
         return self::findFiles($targetFolder, array('php'), $options);
675 675
     }
676 676
     
677
-    public static function findFiles($targetFolder, $extensions=array(), $options=array(), $files=array())
677
+    public static function findFiles($targetFolder, $extensions = array(), $options = array(), $files = array())
678 678
     {
679
-        if(!isset($options['strip-extension'])) {
679
+        if (!isset($options['strip-extension'])) {
680 680
             $options['strip-extension'] = false;
681 681
         }
682 682
         
683
-        if(!isset($options['absolute-path'])) {
683
+        if (!isset($options['absolute-path'])) {
684 684
             $options['absolute-path'] = false;
685 685
         } 
686 686
         
687
-        if(!isset($options['relative-path'])) {
687
+        if (!isset($options['relative-path'])) {
688 688
             $options['relative-path'] = false;
689 689
         }
690 690
         
691
-        if(!isset($options['recursive'])) {
691
+        if (!isset($options['recursive'])) {
692 692
             $options['recursive'] = false;
693 693
         }
694 694
         
695
-        if($options['relative-path']) {
695
+        if ($options['relative-path']) {
696 696
             $options['absolute-path'] = true;
697 697
         }
698 698
         
699
-        if(!isset($options['__root'])) {
699
+        if (!isset($options['__root'])) {
700 700
             $options['__root'] = self::normalizePath($targetFolder);
701 701
         }
702 702
         
703 703
         $checkExtensions = false;
704
-        if(!empty($extensions)) {
704
+        if (!empty($extensions)) {
705 705
             $checkExtensions = true;
706 706
             $extensions = array_map('strtolower', $extensions);
707 707
         }
708 708
         
709
-        if(!is_dir($targetFolder)) 
709
+        if (!is_dir($targetFolder)) 
710 710
         {
711 711
             throw new FileHelper_Exception(
712 712
                 'Target folder does not exist',
@@ -719,32 +719,32 @@  discard block
 block discarded – undo
719 719
         }
720 720
         
721 721
         $d = new \DirectoryIterator($targetFolder);
722
-        foreach($d as $item) {
723
-            if($item->isDot()) {
722
+        foreach ($d as $item) {
723
+            if ($item->isDot()) {
724 724
                 continue;
725 725
             }
726 726
             
727
-            if($item->isDir()) {
728
-                if($options['recursive']) {
727
+            if ($item->isDir()) {
728
+                if ($options['recursive']) {
729 729
                     $files = self::findFiles($item->getPathname(), $extensions, $options, $files);
730 730
                 }
731 731
                 continue;
732 732
             }
733 733
             
734
-            if($checkExtensions && !in_array(self::getExtension($item, true), $extensions)) {
734
+            if ($checkExtensions && !in_array(self::getExtension($item, true), $extensions)) {
735 735
                 continue;
736 736
             }
737 737
             
738 738
             $filename = $item->getFilename();
739
-            if($options['strip-extension']) {
739
+            if ($options['strip-extension']) {
740 740
                 $filename = self::removeExtension($filename);
741 741
             }
742 742
             
743
-            if($options['absolute-path']) {
743
+            if ($options['absolute-path']) {
744 744
                 $filename = self::normalizePath($targetFolder.'/'.$filename);
745 745
             }
746 746
             
747
-            if($options['relative-path']) {
747
+            if ($options['relative-path']) {
748 748
                 $filename = ltrim(str_replace($options['__root'], '', $filename), '/');
749 749
             }
750 750
             
@@ -792,9 +792,9 @@  discard block
 block discarded – undo
792 792
         fclose($fp);
793 793
 
794 794
         $boms = self::getUTFBOMs();
795
-        foreach($boms as $bom => $value) {
795
+        foreach ($boms as $bom => $value) {
796 796
             $length = mb_strlen($value);
797
-            if(mb_substr($text, 0, $length) == $value) {
797
+            if (mb_substr($text, 0, $length) == $value) {
798 798
                 return $bom;
799 799
             }
800 800
         }
@@ -813,13 +813,13 @@  discard block
 block discarded – undo
813 813
     */
814 814
     public static function getUTFBOMs()
815 815
     {
816
-        if(!isset(self::$utfBoms)) {
816
+        if (!isset(self::$utfBoms)) {
817 817
             self::$utfBoms = array(
818
-                'UTF32-BE' => chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF),
819
-                'UTF32-LE' => chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00),
820
-                'UTF16-BE' => chr(0xFE) . chr(0xFF),
821
-                'UTF16-LE' => chr(0xFF) . chr(0xFE),
822
-                'UTF8' => chr(0xEF) . chr(0xBB) . chr(0xBF)
818
+                'UTF32-BE' => chr(0x00).chr(0x00).chr(0xFE).chr(0xFF),
819
+                'UTF32-LE' => chr(0xFF).chr(0xFE).chr(0x00).chr(0x00),
820
+                'UTF16-BE' => chr(0xFE).chr(0xFF),
821
+                'UTF16-LE' => chr(0xFF).chr(0xFE),
822
+                'UTF8' => chr(0xEF).chr(0xBB).chr(0xBF)
823 823
             );
824 824
         }
825 825
         
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
         $encodings = self::getKnownUnicodeEncodings();
841 841
 
842 842
         $keep = array();
843
-        foreach($encodings as $string) 
843
+        foreach ($encodings as $string) 
844 844
         {
845 845
             $withHyphen = str_replace('UTF', 'UTF-', $string);
846 846
             
@@ -871,22 +871,22 @@  discard block
 block discarded – undo
871 871
     */
872 872
     public static function normalizePath($path)
873 873
     {
874
-        if(is_string($path)) {
874
+        if (is_string($path)) {
875 875
             $path = str_replace(array('\\', '//'), array('/', '/'), $path);
876 876
         }
877 877
         
878 878
         return $path;
879 879
     }
880 880
     
881
-    public static function saveAsJSON($data, $file, $pretty=false)
881
+    public static function saveAsJSON($data, $file, $pretty = false)
882 882
     {
883 883
         $options = null;
884
-        if($pretty) {
884
+        if ($pretty) {
885 885
             $options = JSON_PRETTY_PRINT;
886 886
         }
887 887
         
888 888
         $json = json_encode($data, $options);
889
-        if($json===false) 
889
+        if ($json === false) 
890 890
         {
891 891
             $errorCode = json_last_error();
892 892
             throw new FileHelper_Exception(
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
             ); 
897 897
         }
898 898
         
899
-        if(!file_put_contents($file, $json)) {
899
+        if (!file_put_contents($file, $json)) {
900 900
             throw new FileHelper_Exception(
901 901
                 sprintf('Could not write the JSON file [%s] to disk.', basename($file)),
902 902
                 sprintf('Full path: [%s].', $file),
@@ -917,12 +917,12 @@  discard block
 block discarded – undo
917 917
     * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE
918 918
     * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED
919 919
     */
920
-    public static function saveFile(string $filePath, string $content='') : void
920
+    public static function saveFile(string $filePath, string $content = '') : void
921 921
     {
922 922
         // target file already exists
923
-        if(file_exists($filePath))
923
+        if (file_exists($filePath))
924 924
         {
925
-            if(!is_writable($filePath))
925
+            if (!is_writable($filePath))
926 926
             {
927 927
                 throw new FileHelper_Exception(
928 928
                     sprintf('Cannot save file: target file [%s] exists, but is not writable.', basename($filePath)),
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
             // create the folder as needed
943 943
             self::createFolder($targetFolder);
944 944
             
945
-            if(!is_writable($targetFolder)) 
945
+            if (!is_writable($targetFolder)) 
946 946
             {
947 947
                 throw new FileHelper_Exception(
948 948
                     sprintf('Cannot save file: target folder [%s] is not writable.', basename($targetFolder)),
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
             }
956 956
         }
957 957
         
958
-        if(file_put_contents($filePath, $content) !== false) {
958
+        if (file_put_contents($filePath, $content) !== false) {
959 959
             return;
960 960
         }
961 961
         
@@ -991,7 +991,7 @@  discard block
 block discarded – undo
991 991
     {
992 992
         static $checked = array();
993 993
         
994
-        if(isset($checked[$command])) {
994
+        if (isset($checked[$command])) {
995 995
             return $checked[$command];
996 996
         }
997 997
         
@@ -1004,7 +1004,7 @@  discard block
 block discarded – undo
1004 1004
         
1005 1005
         $os = strtolower(PHP_OS_FAMILY);
1006 1006
         
1007
-        if(!isset($osCommands[$os])) 
1007
+        if (!isset($osCommands[$os])) 
1008 1008
         {
1009 1009
             throw new FileHelper_Exception(
1010 1010
                 'Unsupported OS for CLI commands',
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
             $pipes
1031 1031
         );
1032 1032
         
1033
-        if($process === false) {
1033
+        if ($process === false) {
1034 1034
             $checked[$command] = false;
1035 1035
             return false;
1036 1036
         }
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
     */
1062 1062
     public static function checkPHPFileSyntax($path)
1063 1063
     {
1064
-        if(!self::canMakePHPCalls()) {
1064
+        if (!self::canMakePHPCalls()) {
1065 1065
             return true;
1066 1066
         }
1067 1067
         
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
         // when the validation is successful, the first entry
1073 1073
         // in the array contains the success message. When it
1074 1074
         // is invalid, the first entry is always empty.
1075
-        if(!empty($output[0])) {
1075
+        if (!empty($output[0])) {
1076 1076
             return true;
1077 1077
         }
1078 1078
         
@@ -1093,7 +1093,7 @@  discard block
 block discarded – undo
1093 1093
     public static function getModifiedDate($path)
1094 1094
     {
1095 1095
         $time = filemtime($path);
1096
-        if($time !== false) {
1096
+        if ($time !== false) {
1097 1097
             $date = new \DateTime();
1098 1098
             $date->setTimestamp($time);
1099 1099
             return $date;
@@ -1120,7 +1120,7 @@  discard block
 block discarded – undo
1120 1120
     */
1121 1121
     public static function getSubfolders($targetFolder, $options = array())
1122 1122
     {
1123
-        if(!is_dir($targetFolder)) 
1123
+        if (!is_dir($targetFolder)) 
1124 1124
         {
1125 1125
             throw new FileHelper_Exception(
1126 1126
                 'Target folder does not exist',
@@ -1144,29 +1144,29 @@  discard block
 block discarded – undo
1144 1144
         
1145 1145
         $d = new \DirectoryIterator($targetFolder);
1146 1146
         
1147
-        foreach($d as $item) 
1147
+        foreach ($d as $item) 
1148 1148
         {
1149
-            if($item->isDir() && !$item->isDot()) 
1149
+            if ($item->isDir() && !$item->isDot()) 
1150 1150
             {
1151 1151
                 $name = $item->getFilename();
1152 1152
                 
1153
-                if(!$options['absolute-path']) {
1153
+                if (!$options['absolute-path']) {
1154 1154
                     $result[] = $name;
1155 1155
                 } else {
1156 1156
                     $result[] = $targetFolder.'/'.$name;
1157 1157
                 }
1158 1158
                 
1159
-                if(!$options['recursive']) 
1159
+                if (!$options['recursive']) 
1160 1160
                 {
1161 1161
                     continue;
1162 1162
                 }
1163 1163
                 
1164 1164
                 $subs = self::getSubfolders($targetFolder.'/'.$name, $options);
1165
-                foreach($subs as $sub) 
1165
+                foreach ($subs as $sub) 
1166 1166
                 {
1167 1167
                     $relative = $name.'/'.$sub;
1168 1168
                     
1169
-                    if(!$options['absolute-path']) {
1169
+                    if (!$options['absolute-path']) {
1170 1170
                         $result[] = $relative;
1171 1171
                     } else {
1172 1172
                         $result[] = $targetFolder.'/'.$relative;
@@ -1234,7 +1234,7 @@  discard block
 block discarded – undo
1234 1234
     * @param int $depth The folder depth to reduce the path to
1235 1235
     * @return string
1236 1236
     */
1237
-    public static function relativizePathByDepth(string $path, int $depth=2) : string
1237
+    public static function relativizePathByDepth(string $path, int $depth = 2) : string
1238 1238
     {
1239 1239
         $path = self::normalizePath($path);
1240 1240
         
@@ -1242,17 +1242,17 @@  discard block
 block discarded – undo
1242 1242
         $tokens = array_filter($tokens); // remove empty entries (trailing slash for example)
1243 1243
         $tokens = array_values($tokens); // re-index keys
1244 1244
         
1245
-        if(empty($tokens)) {
1245
+        if (empty($tokens)) {
1246 1246
             return '';
1247 1247
         }
1248 1248
         
1249 1249
         // remove the drive if present
1250
-        if(strstr($tokens[0], ':')) {
1250
+        if (strstr($tokens[0], ':')) {
1251 1251
             array_shift($tokens);
1252 1252
         }
1253 1253
         
1254 1254
         // path was only the drive
1255
-        if(count($tokens) == 0) {
1255
+        if (count($tokens) == 0) {
1256 1256
             return '';
1257 1257
         }
1258 1258
 
@@ -1261,8 +1261,8 @@  discard block
 block discarded – undo
1261 1261
         
1262 1262
         // reduce the path to the specified depth
1263 1263
         $length = count($tokens);
1264
-        if($length > $depth) {
1265
-            $tokens = array_slice($tokens, $length-$depth);
1264
+        if ($length > $depth) {
1265
+            $tokens = array_slice($tokens, $length - $depth);
1266 1266
         }
1267 1267
 
1268 1268
         // append the last element again
@@ -1310,14 +1310,14 @@  discard block
 block discarded – undo
1310 1310
     * 
1311 1311
     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1312 1312
     */
1313
-    public static function requireFileExists(string $path, $errorCode=null) : string
1313
+    public static function requireFileExists(string $path, $errorCode = null) : string
1314 1314
     {
1315 1315
         $result = realpath($path);
1316
-        if($result !== false) {
1316
+        if ($result !== false) {
1317 1317
             return $result;
1318 1318
         }
1319 1319
         
1320
-        if($errorCode === null) {
1320
+        if ($errorCode === null) {
1321 1321
             $errorCode = self::ERROR_FILE_DOES_NOT_EXIST;
1322 1322
         }
1323 1323
         
@@ -1346,15 +1346,15 @@  discard block
 block discarded – undo
1346 1346
         
1347 1347
         $file = new \SplFileObject($path);
1348 1348
         
1349
-        if($file->eof()) {
1349
+        if ($file->eof()) {
1350 1350
             return '';
1351 1351
         }
1352 1352
         
1353
-        $targetLine = $lineNumber-1;
1353
+        $targetLine = $lineNumber - 1;
1354 1354
         
1355 1355
         $file->seek($targetLine);
1356 1356
         
1357
-        if($file->key() !== $targetLine) {
1357
+        if ($file->key() !== $targetLine) {
1358 1358
              return null;
1359 1359
         }
1360 1360
         
@@ -1380,7 +1380,7 @@  discard block
 block discarded – undo
1380 1380
         $number = $spl->key();
1381 1381
         
1382 1382
         // if seeking to the end the cursor is still at 0, there are no lines. 
1383
-        if($number === 0) 
1383
+        if ($number === 0) 
1384 1384
         {
1385 1385
             // since it's a very small file, to get reliable results,
1386 1386
             // we read its contents and use that to determine what
@@ -1388,13 +1388,13 @@  discard block
 block discarded – undo
1388 1388
             // that this is not pactical to solve with the SplFileObject.
1389 1389
             $content = file_get_contents($path);
1390 1390
             
1391
-            if(empty($content)) {
1391
+            if (empty($content)) {
1392 1392
                 return 0;
1393 1393
             }
1394 1394
         }
1395 1395
         
1396 1396
         // return the line number we were able to reach + 1 (key is zero-based)
1397
-        return $number+1;
1397
+        return $number + 1;
1398 1398
     }
1399 1399
     
1400 1400
    /**
@@ -1441,13 +1441,13 @@  discard block
 block discarded – undo
1441 1441
     * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES
1442 1442
     * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST
1443 1443
     */
1444
-    public static function readLines(string $filePath, int $amount=0) : array
1444
+    public static function readLines(string $filePath, int $amount = 0) : array
1445 1445
     {
1446 1446
         self::requireFileExists($filePath);
1447 1447
         
1448 1448
         $fn = fopen($filePath, "r");
1449 1449
         
1450
-        if($fn === false) 
1450
+        if ($fn === false) 
1451 1451
         {
1452 1452
             throw new FileHelper_Exception(
1453 1453
                 'Could not open file for reading.',
@@ -1463,25 +1463,25 @@  discard block
 block discarded – undo
1463 1463
         $counter = 0;
1464 1464
         $first = true;
1465 1465
         
1466
-        while(!feof($fn)) 
1466
+        while (!feof($fn)) 
1467 1467
         {
1468 1468
             $counter++;
1469 1469
             
1470 1470
             $line = fgets($fn);
1471 1471
             
1472 1472
             // can happen with zero length files
1473
-            if($line === false) {
1473
+            if ($line === false) {
1474 1474
                 continue;
1475 1475
             }
1476 1476
             
1477 1477
             // the first line may contain a unicode BOM marker.
1478
-            if($first) {
1478
+            if ($first) {
1479 1479
                 $line = ConvertHelper::stripUTFBom($line);
1480 1480
             }
1481 1481
             
1482 1482
             $result[] = $line;
1483 1483
             
1484
-            if($amount > 0 && $counter == $amount) {
1484
+            if ($amount > 0 && $counter == $amount) {
1485 1485
                 break;
1486 1486
             }
1487 1487
         }
@@ -1507,7 +1507,7 @@  discard block
 block discarded – undo
1507 1507
         
1508 1508
         $result = file_get_contents($filePath);
1509 1509
         
1510
-        if($result !== false) {
1510
+        if ($result !== false) {
1511 1511
             return $result;
1512 1512
         }
1513 1513
         
Please login to merge, or discard this patch.
examples/URLInfo/highlighting.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@
 block discarded – undo
42 42
 		<br>
43 43
         <?php
44 44
         
45
-            foreach($urls as $url)
45
+            foreach ($urls as $url)
46 46
             {
47 47
                 $info = parseURL($url);
48 48
                 
Please login to merge, or discard this patch.
examples/prepend.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
     $autoload = realpath($root.'/../vendor/autoload.php');
13 13
     
14 14
     // we need the autoloader to be present
15
-    if($autoload === false) 
15
+    if ($autoload === false) 
16 16
     {
17 17
         die('<b>ERROR:</b> Autoloader not present. Run composer update first.');
18 18
     }
Please login to merge, or discard this patch.