Passed
Push — master ( 3fc76b...c4daa3 )
by f
14:51
created
src/PclZipInterface.php 1 patch
Braces   +99 added lines, -57 removed lines patch added patch discarded remove patch
@@ -142,8 +142,11 @@  discard block
 block discarded – undo
142 142
      */
143 143
     public function create($content)
144 144
     {
145
-        if (is_array($content)) $paths_list = $content;
146
-        else $paths_list = explode(',', $content);
145
+        if (is_array($content)) {
146
+         $paths_list = $content;
147
+        } else {
148
+         $paths_list = explode(',', $content);
149
+        }
147 150
 
148 151
         $options = $this->makeOptionsFromArguments(func_get_args());
149 152
 
@@ -151,8 +154,9 @@  discard block
 block discarded – undo
151 154
         $filters = $this->createFilters($options);
152 155
         list($preAddCallback, $postAddCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_ADD, PCLZIP_CB_POST_ADD);
153 156
 
154
-        if (!empty($comment = $this->buildComment($options, null)))
155
-            $this->archive->setComment($comment);
157
+        if (!empty($comment = $this->buildComment($options, null))) {
158
+                    $this->archive->setComment($comment);
159
+        }
156 160
 
157 161
         // scan filesystem for files list
158 162
         return $this->addSnippets($paths_list, $filters, $preAddCallback, $postAddCallback);
@@ -172,16 +176,18 @@  discard block
 block discarded – undo
172 176
             $localname = $fileToAdd;
173 177
             $filename = $fileToAdd;
174 178
 
175
-            foreach ($filters as $filter)
176
-                call_user_func($filter, $localname, $filename);
179
+            foreach ($filters as $filter) {
180
+                            call_user_func($filter, $localname, $filename);
181
+            }
177 182
 
178 183
             $file_header = $this->createFileHeader($localname, $filename);
179 184
             if (call_user_func($preAddCallback, $file_header) == 1) {
180 185
                 //
181 186
                 // Check for max length > 255
182 187
                 //
183
-                if (strlen(basename($file_header->stored_filename)) > 255)
184
-                    $file_header->status = 'filename_too_long';
188
+                if (strlen(basename($file_header->stored_filename)) > 255) {
189
+                                    $file_header->status = 'filename_too_long';
190
+                }
185 191
                 if (is_file($filename)) {
186 192
                     $this->archive->add([
187 193
                         $file_header->stored_filename => $file_header->filename,
@@ -253,27 +259,35 @@  discard block
 block discarded – undo
253 259
         }
254 260
 
255 261
         // filters initiation
256
-        if (isset($options[PCLZIP_OPT_PATH]))
257
-            $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/');
258
-        else $extractPath = rtrim(getcwd(), '/');
262
+        if (isset($options[PCLZIP_OPT_PATH])) {
263
+                    $extractPath = rtrim($options[PCLZIP_OPT_PATH], '/');
264
+        } else {
265
+         $extractPath = rtrim(getcwd(), '/');
266
+        }
259 267
 
260 268
         $filters = $this->createFilters($options);
261 269
         list($preExtractCallback, $postExtractCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_EXTRACT, PCLZIP_CB_POST_EXTRACT);
262 270
         $selectFilter = $this->createSelector($options);
263 271
 
264
-        if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING]))
265
-            $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING;
266
-        else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT]))
267
-            $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT;
268
-        else $anotherOutputFormat = false;
272
+        if (isset($options[PCLZIP_OPT_EXTRACT_AS_STRING])) {
273
+                    $anotherOutputFormat = PCLZIP_OPT_EXTRACT_AS_STRING;
274
+        } else if (isset($options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
275
+                    $anotherOutputFormat = PCLZIP_OPT_EXTRACT_IN_OUTPUT;
276
+        } else {
277
+         $anotherOutputFormat = false;
278
+        }
269 279
 
270
-        if (isset($options[PCLZIP_OPT_REPLACE_NEWER]))
271
-            $doNotReplaceNewer = false;
272
-        else $doNotReplaceNewer = true;
280
+        if (isset($options[PCLZIP_OPT_REPLACE_NEWER])) {
281
+                    $doNotReplaceNewer = false;
282
+        } else {
283
+         $doNotReplaceNewer = true;
284
+        }
273 285
 
274
-        if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION]))
275
-            $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION];
276
-        else $restrictExtractDir = false;
286
+        if (isset($options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION])) {
287
+                    $restrictExtractDir = $options[PCLZIP_OPT_EXTRACT_DIR_RESTRICTION];
288
+        } else {
289
+         $restrictExtractDir = false;
290
+        }
277 291
 
278 292
         $report = array();
279 293
         foreach ($this->listContent() as $file_header) {
@@ -344,8 +358,10 @@  discard block
 block discarded – undo
344 358
             // extract content
345 359
             else if ($anotherOutputFormat === false) {
346 360
                 // apply path filters
347
-                foreach ($filters as $filter) call_user_func($filter,
361
+                foreach ($filters as $filter) {
362
+                 call_user_func($filter,
348 363
                     $file_header->stored_filename, $file_header->filename);
364
+                }
349 365
                 // dir extraction process
350 366
                 if ($file_header->folder) {
351 367
                     // if dir doesn't exist
@@ -436,15 +452,19 @@  discard block
 block discarded – undo
436 452
      */
437 453
     public function add($content)
438 454
     {
439
-        if (is_array($content)) $paths_list = $content;
440
-        else $paths_list = explode(',', $content);
455
+        if (is_array($content)) {
456
+         $paths_list = $content;
457
+        } else {
458
+         $paths_list = explode(',', $content);
459
+        }
441 460
 
442 461
         $options = $this->makeOptionsFromArguments(func_get_args());
443 462
         $filters = $this->createFilters($options);
444 463
         list($preAddCallback, $postAddCallback) = $this->extractCallbacks($options, PCLZIP_CB_PRE_ADD, PCLZIP_CB_POST_ADD);
445 464
 
446
-        if (!empty($comment = $this->buildComment($options, $this->archive->getComment())))
447
-            $this->archive->setComment($comment);
465
+        if (!empty($comment = $this->buildComment($options, $this->archive->getComment()))) {
466
+                    $this->archive->setComment($comment);
467
+        }
448 468
 
449 469
         // scan filesystem for files list
450 470
         return $this->addSnippets($paths_list, $filters, $preAddCallback, $postAddCallback);
@@ -516,8 +536,12 @@  discard block
 block discarded – undo
516 536
         }
517 537
 
518 538
         $tempDir = tempnam(PCLZIP_TEMPORARY_DIR, 'merging');
519
-        if (file_exists($tempDir)) unlink($tempDir);
520
-        if (!mkdir($tempDir)) return 0;
539
+        if (file_exists($tempDir)) {
540
+         unlink($tempDir);
541
+        }
542
+        if (!mkdir($tempDir)) {
543
+         return 0;
544
+        }
521 545
 
522 546
         // go through archive content list and copy all files
523 547
         foreach ($a->getFiles() as $filename) {
@@ -545,8 +569,11 @@  discard block
 block discarded – undo
545 569
 
546 570
         call_user_func(function ($directory) {
547 571
             foreach (glob($directory.'/*') as $f) {
548
-                if (is_dir($f)) call_user_func(__FUNCTION__, $f);
549
-                else unlink($f);
572
+                if (is_dir($f)) {
573
+                 call_user_func(__FUNCTION__, $f);
574
+                } else {
575
+                 unlink($f);
576
+                }
550 577
             }
551 578
         }, $tempDir);
552 579
 
@@ -571,18 +598,21 @@  discard block
 block discarded – undo
571 598
     {
572 599
         $filters = array();
573 600
         if (isset($options[PCLZIP_OPT_REMOVE_PATH])
574
-            && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH]))
575
-            $filters[] = function (&$key, &$value) use ($options) {
601
+            && !isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
602
+                    $filters[] = function (&$key, &$value) use ($options) {
576 603
                 $key = str_replace($key, null, $key);
604
+        }
577 605
             };
578
-        if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH]))
579
-            $filters[] = function (&$key, &$value) {
606
+        if (isset($options[PCLZIP_OPT_REMOVE_ALL_PATH])) {
607
+                    $filters[] = function (&$key, &$value) {
580 608
                 $key = basename($key);
609
+        }
581 610
             };
582
-        if (isset($options[PCLZIP_OPT_ADD_PATH]))
583
-            $filters[] = function (&$key, &$value) use ($options) {
611
+        if (isset($options[PCLZIP_OPT_ADD_PATH])) {
612
+                    $filters[] = function (&$key, &$value) use ($options) {
584 613
                 $key = rtrim($options[PCLZIP_OPT_ADD_PATH], '/') . '/' .
585 614
                     ltrim($key, '/');
615
+        }
586 616
             };
587 617
         return $filters;
588 618
     }
@@ -597,11 +627,13 @@  discard block
 block discarded – undo
597 627
     {
598 628
         $preCallback = $postCallback = function () { return true; };
599 629
 
600
-        if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst]))
601
-            $preCallback = $options[$preCallbackConst];
630
+        if (isset($options[$preCallbackConst]) && is_callable($options[$preCallbackConst])) {
631
+                    $preCallback = $options[$preCallbackConst];
632
+        }
602 633
 
603
-        if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst]))
604
-            $postCallback = $options[$postCallbackConst];
634
+        if (isset($options[$postCallbackConst]) && is_callable($options[$postCallbackConst])) {
635
+                    $postCallback = $options[$postCallbackConst];
636
+        }
605 637
 
606 638
         return [$preCallback, $postCallback];
607 639
     }
@@ -615,7 +647,9 @@  discard block
 block discarded – undo
615 647
         // @todo create version for 5.5 of ARRAY_FILTER_USE_KEY function or drop 5.5 support
616 648
         $keys = array_filter($options, function ($v) {return ($v%2) == 0;}, ARRAY_FILTER_USE_KEY);
617 649
         $values = array_filter($options, function ($v) {return ($v%2) == 1;}, ARRAY_FILTER_USE_KEY);
618
-        if (count($values) < count($keys)) $values[] = true;
650
+        if (count($values) < count($keys)) {
651
+         $values[] = true;
652
+        }
619 653
         return array_combine($keys, $values);
620 654
     }
621 655
 
@@ -658,9 +692,12 @@  discard block
 block discarded – undo
658 692
         $allowedIndexes = array();
659 693
         foreach ($indexes as $rule) {
660 694
             $parts = explode('-', $rule);
661
-            if (count($parts) == 1) $allowedIndexes[] = $rule;
662
-            else $allowedIndexes = array_merge(
695
+            if (count($parts) == 1) {
696
+             $allowedIndexes[] = $rule;
697
+            } else {
698
+             $allowedIndexes = array_merge(
663 699
                 range($parts[0], $parts[1]), $allowedIndexes);
700
+            }
664 701
         }
665 702
 
666 703
         return function ($key, $value, $index) use ($allowedIndexes) {
@@ -735,21 +772,26 @@  discard block
 block discarded – undo
735 772
     protected function createSelector(array $options)
736 773
     {
737 774
         // exact matching
738
-        if (isset($options[PCLZIP_OPT_BY_NAME]))
739
-            $selectFilter = $this->createByNameSelector($options[PCLZIP_OPT_BY_NAME]);
775
+        if (isset($options[PCLZIP_OPT_BY_NAME])) {
776
+                    $selectFilter = $this->createByNameSelector($options[PCLZIP_OPT_BY_NAME]);
777
+        }
740 778
         // <ereg> rule
741
-        else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg'))
742
-            $selectFilter = $this->createByEregSelector($options[PCLZIP_OPT_BY_EREG]);
779
+        else if (isset($options[PCLZIP_OPT_BY_EREG]) && function_exists('ereg')) {
780
+                    $selectFilter = $this->createByEregSelector($options[PCLZIP_OPT_BY_EREG]);
781
+        }
743 782
         // <preg_match> rule
744
-        else if (isset($options[PCLZIP_OPT_BY_PREG]))
745
-            $selectFilter = $this->createByPregSelector($options[PCLZIP_OPT_BY_PREG]);
783
+        else if (isset($options[PCLZIP_OPT_BY_PREG])) {
784
+                    $selectFilter = $this->createByPregSelector($options[PCLZIP_OPT_BY_PREG]);
785
+        }
746 786
         // index rule
747
-        else if (isset($options[PCLZIP_OPT_BY_INDEX]))
748
-            $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]);
787
+        else if (isset($options[PCLZIP_OPT_BY_INDEX])) {
788
+                    $selectFilter = $this->createByIndexSelector($options[PCLZIP_OPT_BY_INDEX]);
789
+        }
749 790
         // no rule
750
-        else
751
-            $selectFilter = function () {
791
+        else {
792
+                    $selectFilter = function () {
752 793
                 return self::SELECT_FILTER_PASS;
794
+        }
753 795
             };
754 796
         return $selectFilter;
755 797
     }
@@ -785,9 +827,9 @@  discard block
 block discarded – undo
785 827
     protected function buildComment(array $options, $currentComment)
786 828
     {
787 829
         $comment = null;
788
-        if (isset($options[PCLZIP_OPT_COMMENT]))
789
-            $comment = $options[PCLZIP_OPT_COMMENT];
790
-        else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {;
830
+        if (isset($options[PCLZIP_OPT_COMMENT])) {
831
+                    $comment = $options[PCLZIP_OPT_COMMENT];
832
+        } else if (isset($options[PCLZIP_OPT_ADD_COMMENT])) {;
791 833
             $comment = $currentComment . $options[PCLZIP_OPT_ADD_COMMENT];
792 834
         } else if (isset($options[PCLZIP_OPT_PREPEND_COMMENT])) {
793 835
             $comment = $options[PCLZIP_OPT_PREPEND_COMMENT] . $currentComment;
Please login to merge, or discard this patch.
src/UnifiedArchive.php 1 patch
Braces   +21 added lines, -15 removed lines patch added patch discarded remove patch
@@ -459,13 +459,15 @@  discard block
 block discarded – undo
459 459
      */
460 460
     public function getFiles($filter = null)
461 461
     {
462
-        if ($filter === null)
463
-            return $this->files;
462
+        if ($filter === null) {
463
+                    return $this->files;
464
+        }
464 465
 
465 466
         $result = [];
466 467
         foreach ($this->files as $file) {
467
-            if (fnmatch($filter, $file))
468
-                $result[] = $file;
468
+            if (fnmatch($filter, $file)) {
469
+                            $result[] = $file;
470
+            }
469 471
         }
470 472
         return $result;
471 473
     }
@@ -667,9 +669,9 @@  discard block
 block discarded – undo
667 669
         if (is_array($nodes)) {
668 670
             foreach ($nodes as $destination => $source) {
669 671
                 // new format
670
-                if (is_numeric($destination))
671
-                    $destination = $source;
672
-                else {
672
+                if (is_numeric($destination)) {
673
+                                    $destination = $source;
674
+                } else {
673 675
                     // old format
674 676
                     if (is_string($source) && !file_exists($source)) {
675 677
                         list($destination, $source) = [$source, $destination];
@@ -728,8 +730,9 @@  discard block
 block discarded – undo
728 730
         // $map[$destination] = rtrim($source, '/*');
729 731
         // do not map root archive folder
730 732
 
731
-        if ($destination !== null)
732
-            $map[$destination] = null;
733
+        if ($destination !== null) {
734
+                    $map[$destination] = null;
735
+        }
733 736
 
734 737
         foreach (glob($source, GLOB_MARK) as $node) {
735 738
             if (in_array(substr($node, -1), ['/', '\\'], true) && $recursive) {
@@ -975,8 +978,9 @@  discard block
 block discarded – undo
975 978
      */
976 979
     public static function archiveDirectory($directory, $archiveName, $compressionLevel = BasicDriver::COMPRESSION_AVERAGE, $password = null)
977 980
     {
978
-        if (!is_dir($directory) || !is_readable($directory))
979
-            throw new InvalidArgumentException($directory . ' is not a valid directory to archive');
981
+        if (!is_dir($directory) || !is_readable($directory)) {
982
+                    throw new InvalidArgumentException($directory . ' is not a valid directory to archive');
983
+        }
980 984
 
981 985
         return static::create($directory, $archiveName, $compressionLevel, $password) > 0;
982 986
     }
@@ -1137,8 +1141,9 @@  discard block
 block discarded – undo
1137 1141
      */
1138 1142
     public function addFile($file, $inArchiveName = null)
1139 1143
     {
1140
-        if (!is_file($file))
1141
-            throw new InvalidArgumentException($file . ' is not a valid file to add in archive');
1144
+        if (!is_file($file)) {
1145
+                    throw new InvalidArgumentException($file . ' is not a valid file to add in archive');
1146
+        }
1142 1147
 
1143 1148
         return ($inArchiveName !== null
1144 1149
                 ? $this->add([$inArchiveName => $file])
@@ -1158,8 +1163,9 @@  discard block
 block discarded – undo
1158 1163
      */
1159 1164
     public function addDirectory($directory, $inArchivePath = null)
1160 1165
     {
1161
-        if (!is_dir($directory) || !is_readable($directory))
1162
-            throw new InvalidArgumentException($directory . ' is not a valid directory to add in archive');
1166
+        if (!is_dir($directory) || !is_readable($directory)) {
1167
+                    throw new InvalidArgumentException($directory . ' is not a valid directory to add in archive');
1168
+        }
1163 1169
 
1164 1170
         return ($inArchivePath !== null
1165 1171
                 ? $this->add([$inArchivePath => $directory])
Please login to merge, or discard this patch.
src/Commands/InfoCommand.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,8 +34,9 @@
 block discarded – undo
34 34
         $output->writeln("\t". 'uncompressed: '.implode(' ', $this->formatSize($archive->getOriginalSize(), 2)));
35 35
         $output->writeln("\t" . 'compressed: ' . implode(' ', $this->formatSize($archive->getCompressedSize(), 2)));
36 36
         $output->writeln("\t" . 'ratio: <info>' . round($archive->getOriginalSize() / $archive->getCompressedSize(), 6) . '/1 (' . floor($archive->getCompressedSize() / $archive->getOriginalSize() * 100) . '%</info>)');
37
-        if ($archive->getDriver()->checkAbility(Abilities::GET_COMMENT) && !empty($comment = $archive->getComment()))
38
-            $output->writeln('Comment: <comment>' . $comment . '</comment>');
37
+        if ($archive->getDriver()->checkAbility(Abilities::GET_COMMENT) && !empty($comment = $archive->getComment())) {
38
+                    $output->writeln('Comment: <comment>' . $comment . '</comment>');
39
+        }
39 40
 
40 41
         return 0;
41 42
     }
Please login to merge, or discard this patch.