bcit-ci/CodeIgniter

View on GitHub
system/libraries/Upload.php

Summary

Maintainability
F
6 days
Test Coverage

File Upload.php has 621 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP
Severity: Major
Found in system/libraries/Upload.php - About 1 day to fix

    Function do_upload has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

        public function do_upload($field = 'userfile')
        {
            // Is $_FILES[$field] set? If not, no reason to continue.
            if (isset($_FILES[$field]))
            {
    Severity: Minor
    Found in system/libraries/Upload.php - About 6 hrs 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 _file_mime_type has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function _file_mime_type($file)
        {
            // We'll need this to validate the MIME info string (e.g. text/plain; charset=us-ascii)
            $regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/';
    
    
    Severity: Minor
    Found in system/libraries/Upload.php - About 5 hrs 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 do_upload has 138 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function do_upload($field = 'userfile')
        {
            // Is $_FILES[$field] set? If not, no reason to continue.
            if (isset($_FILES[$field]))
            {
    Severity: Major
    Found in system/libraries/Upload.php - About 5 hrs to fix

      Function initialize has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          public function initialize(array $config = array(), $reset = TRUE)
          {
              $reflection = new ReflectionClass($this);
      
              if ($reset === TRUE)
      Severity: Minor
      Found in system/libraries/Upload.php - About 4 hrs 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

      CI_Upload has 28 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class CI_Upload {
      
          /**
           * Maximum file size
           *
      Severity: Minor
      Found in system/libraries/Upload.php - About 3 hrs to fix

        Method _file_mime_type has 68 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function _file_mime_type($file)
            {
                // We'll need this to validate the MIME info string (e.g. text/plain; charset=us-ascii)
                $regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/';
        
        
        Severity: Major
        Found in system/libraries/Upload.php - About 2 hrs to fix

          Method initialize has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function initialize(array $config = array(), $reset = TRUE)
              {
                  $reflection = new ReflectionClass($this);
          
                  if ($reset === TRUE)
          Severity: Minor
          Found in system/libraries/Upload.php - About 1 hr to fix

            Method do_xss_clean has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function do_xss_clean()
                {
                    $file = $this->file_temp;
            
                    if (filesize($file) == 0)
            Severity: Minor
            Found in system/libraries/Upload.php - About 1 hr to fix

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

                  public function do_xss_clean()
                  {
                      $file = $this->file_temp;
              
                      if (filesize($file) == 0)
              Severity: Minor
              Found in system/libraries/Upload.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 is_allowed_dimensions has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function is_allowed_dimensions()
                  {
                      if ( ! $this->is_image())
                      {
                          return TRUE;
              Severity: Minor
              Found in system/libraries/Upload.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 is_allowed_filetype has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function is_allowed_filetype($ignore_mime = FALSE)
                  {
                      if ($this->allowed_types === '*')
                      {
                          return TRUE;
              Severity: Minor
              Found in system/libraries/Upload.php - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                                        if (preg_match($regexp, $mime[(count($mime) - 1)], $matches))
                                        {
                                            $this->file_type = $matches[1];
                                            return;
                                        }
                Severity: Major
                Found in system/libraries/Upload.php - About 45 mins to fix

                  Function is_allowed_filetype has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function is_allowed_filetype($ignore_mime = FALSE)
                      {
                          if ($this->allowed_types === '*')
                          {
                              return TRUE;
                  Severity: Minor
                  Found in system/libraries/Upload.php - About 35 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 set_filename has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function set_filename($path, $filename)
                      {
                          if ($this->encrypt_name === TRUE)
                          {
                              $filename = md5(uniqid(mt_rand())).$this->file_ext;
                  Severity: Minor
                  Found in system/libraries/Upload.php - About 35 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 FALSE;
                  Severity: Major
                  Found in system/libraries/Upload.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return FALSE;
                    Severity: Major
                    Found in system/libraries/Upload.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return FALSE;
                      Severity: Major
                      Found in system/libraries/Upload.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return is_array($this->_mimes[$ext])
                                        ? in_array($this->file_type, $this->_mimes[$ext], TRUE)
                                        : ($this->_mimes[$ext] === $this->file_type);
                        Severity: Major
                        Found in system/libraries/Upload.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return FALSE;
                          Severity: Major
                          Found in system/libraries/Upload.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                    return $this->_CI->security->xss_clean($data, TRUE);
                            Severity: Major
                            Found in system/libraries/Upload.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return FALSE;
                              Severity: Major
                              Found in system/libraries/Upload.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return;
                                Severity: Major
                                Found in system/libraries/Upload.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                          return TRUE;
                                  Severity: Major
                                  Found in system/libraries/Upload.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                return FALSE;
                                    Severity: Major
                                    Found in system/libraries/Upload.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                  return TRUE;
                                      Severity: Major
                                      Found in system/libraries/Upload.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                return FALSE;
                                        Severity: Major
                                        Found in system/libraries/Upload.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                  return TRUE;
                                          Severity: Major
                                          Found in system/libraries/Upload.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                            return FALSE;
                                            Severity: Major
                                            Found in system/libraries/Upload.php - About 30 mins to fix

                                              There are no issues that match your filters.

                                              Category
                                              Status