Kylob/BootPress

View on GitHub
src/Unzip/Component.php

Summary

Maintainability
F
3 days
Test Coverage

File Component.php has 340 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace BootPress\Unzip;

use BootPress\Page\Component as Page;
Severity: Minor
Found in src/Unzip/Component.php - About 4 hrs to fix

    Method loadFileListByEof has 93 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function loadFileListByEof()
        {
            // Check if there's a valid Central Dir signature.
            // Let's consider a file comment smaller than 1024 characters...
            // Actually, it length can be 65536.. But we're not going to support it.
    Severity: Major
    Found in src/Unzip/Component.php - About 3 hrs to fix

      Method getFileHeader has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function getFileHeader($start_offset = false)
          {
              if ($start_offset !== false) {
                  fseek($this->fh, $start_offset);
              }
      Severity: Minor
      Found in src/Unzip/Component.php - About 1 hr to fix

        Function loadFileListByEof has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            private function loadFileListByEof()
            {
                // Check if there's a valid Central Dir signature.
                // Let's consider a file comment smaller than 1024 characters...
                // Actually, it length can be 65536.. But we're not going to support it.
        Severity: Minor
        Found in src/Unzip/Component.php - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function extractFolders has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            public function extractFolders($folders, $allow_extensions = null)
            {
                $file_locations = array();
                foreach ((array) $folders as $folder) {
                    foreach ($this->files() as $file) {
        Severity: Minor
        Found in src/Unzip/Component.php - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function mkpath has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            private function mkpath($dir)
            {
                $path = $this->dir.$dir;
                if (!is_dir($path)) {
                    $str = '';
        Severity: Minor
        Found in src/Unzip/Component.php - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method uncompress has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function uncompress($content, $mode, $uncompressed_size, $target_file_name)
            {
                switch ($mode) {
                    case 0:
                        return ($target_file_name) ? file_put_contents($target_file_name, $content) : $content;
        Severity: Minor
        Found in src/Unzip/Component.php - About 1 hr to fix

          Function extractFiles has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function extractFiles($files)
              {
                  $file_locations = array();
                  foreach ((array) $files as $extract) {
                      foreach ($this->files() as $file) {
          Severity: Minor
          Found in src/Unzip/Component.php - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function extract has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public function extract($allow_extensions = null, $remove_common_dir = false)
              {
                  $locations = array();
                  $files = $this->files();
                  $start = $remove_common_dir ? mb_strlen(Page::html()->commonDir($files)) : 0;
          Severity: Minor
          Found in src/Unzip/Component.php - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Avoid too many return statements within this method.
          Open

                          return ($target_file_name) ? file_put_contents($target_file_name, bzdecompress($content)) : bzdecompress($content);
          Severity: Major
          Found in src/Unzip/Component.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                            return $this->setError('IBM TERSE is not supported... yet?');
            Severity: Major
            Found in src/Unzip/Component.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $ret;
              Severity: Major
              Found in src/Unzip/Component.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return $this->setError('Enhanced Deflating is not supported... yet?');
                Severity: Major
                Found in src/Unzip/Component.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  return $this->setError('PKWARE Date Compression Library Impoloding is not supported... yet?');
                  Severity: Major
                  Found in src/Unzip/Component.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return $this->setError('Unknown uncompress method: '.$mode);
                    Severity: Major
                    Found in src/Unzip/Component.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return $this->setError('Tokenizing compression algorithm is not supported... yet?');
                      Severity: Major
                      Found in src/Unzip/Component.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return ($target_file_name) ? file_put_contents($target_file_name, gzinflate($content, $uncompressed_size)) : gzinflate($content, $uncompressed_size);
                        Severity: Major
                        Found in src/Unzip/Component.php - About 30 mins to fix

                          Function loadFilesBySignatures has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              private function loadFilesBySignatures()
                              {
                                  $return = false;
                                  fseek($this->fh, 0);
                                  for (; ;) {
                          Severity: Minor
                          Found in src/Unzip/Component.php - About 25 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                                                  'crc-32' => str_pad(dechex(ord($dir['crc-32'][3])), 2, '0', STR_PAD_LEFT).
                                                  str_pad(dechex(ord($dir['crc-32'][2])), 2, '0', STR_PAD_LEFT).
                                                  str_pad(dechex(ord($dir['crc-32'][1])), 2, '0', STR_PAD_LEFT).
                                                  str_pad(dechex(ord($dir['crc-32'][0])), 2, '0', STR_PAD_LEFT),
                          Severity: Major
                          Found in src/Unzip/Component.php and 1 other location - About 4 hrs to fix
                          src/Unzip/Component.php on lines 438..441

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 181.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Similar blocks of code found in 2 locations. Consider refactoring.
                          Open

                                          'crc-32' => str_pad(dechex(ord($file['crc-32'][3])), 2, '0', STR_PAD_LEFT).
                                          str_pad(dechex(ord($file['crc-32'][2])), 2, '0', STR_PAD_LEFT).
                                          str_pad(dechex(ord($file['crc-32'][1])), 2, '0', STR_PAD_LEFT).
                                          str_pad(dechex(ord($file['crc-32'][0])), 2, '0', STR_PAD_LEFT),
                          Severity: Major
                          Found in src/Unzip/Component.php and 1 other location - About 4 hrs to fix
                          src/Unzip/Component.php on lines 327..330

                          Duplicated Code

                          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                          Tuning

                          This issue has a mass of 181.

                          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                          Refactorings

                          Further Reading

                          Space found before second semicolon of FOR loop
                          Open

                                  for (; ;) {
                          Severity: Minor
                          Found in src/Unzip/Component.php by phpcodesniffer

                          The method __destroy is not named in camelCase.
                          Open

                              public function __destroy()
                              {
                                  $this->close();
                              }
                          Severity: Minor
                          Found in src/Unzip/Component.php by phpmd

                          CamelCaseMethodName

                          Since: 0.2

                          It is considered best practice to use the camelCase notation to name methods.

                          Example

                          class ClassName {
                              public function get_name() {
                              }
                          }

                          Source

                          There are no issues that match your filters.

                          Category
                          Status