XoopsModules25x/smallworld

View on GitHub
class/UploadHandler.php

Summary

Maintainability
F
5 days
Test Coverage

File UploadHandler.php has 647 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace XoopsModules\Smallworld;

/*
Severity: Major
Found in class/UploadHandler.php - About 1 day to fix

    UploadHandler has 42 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class UploadHandler
    {
        protected $options;
    
        // PHP File Upload error message codes:
    Severity: Minor
    Found in class/UploadHandler.php - About 5 hrs to fix

      Function handle_file_upload has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function handle_file_upload(
              $uploaded_file,
              $name,
              $size,
              $type,
      Severity: Minor
      Found in class/UploadHandler.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

      Function validate has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function validate($uploaded_file, $file, $error, $index)
          {
              if ($error) {
                  $file->error = $this->get_error_message($error);
      
      
      Severity: Minor
      Found in class/UploadHandler.php - About 2 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 create_scaled_image has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function create_scaled_image($file_name, $version, $options)
          {
              $file_path = $this->get_upload_path($file_name);
              if (!empty($version)) {
                  $version_dir = $this->get_upload_path(null, $version);
      Severity: Minor
      Found in class/UploadHandler.php - About 2 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 create_scaled_image has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function create_scaled_image($file_name, $version, $options)
          {
              $file_path = $this->get_upload_path($file_name);
              if (!empty($version)) {
                  $version_dir = $this->get_upload_path(null, $version);
      Severity: Major
      Found in class/UploadHandler.php - About 2 hrs to fix

        Method __construct has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function __construct($options = null, $initialize = true)
            {
                $userID = $GLOBALS['xoopsUser']->getVar('uid');
                $this->options = [
                    'script_url'                       => $this->get_full_url() . '/imgupload.php',
        Severity: Major
        Found in class/UploadHandler.php - About 2 hrs to fix

          Method handle_file_upload has 52 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function handle_file_upload(
                  $uploaded_file,
                  $name,
                  $size,
                  $type,
          Severity: Major
          Found in class/UploadHandler.php - About 2 hrs to fix

            Method validate has 51 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function validate($uploaded_file, $file, $error, $index)
                {
                    if ($error) {
                        $file->error = $this->get_error_message($error);
            
            
            Severity: Major
            Found in class/UploadHandler.php - About 2 hrs to fix

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

                  public function delete($print_response = true)
                  {
                      $userid    = $GLOBALS['xoopsUser']->getVar('uid');
                      $swDB      = new SwDatabase();
                      $file_name = $this->get_file_name_param();
              Severity: Minor
              Found in class/UploadHandler.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 orient_image has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function orient_image($file_path)
                  {
                      if (!function_exists('exif_read_data')) {
                          return false;
                      }
              Severity: Minor
              Found in class/UploadHandler.php - About 1 hr to fix

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

                    protected function get_file_object($file_name)
                    {
                        if ($this->is_valid_file_object($file_name)) {
                            $file       = new \stdClass();
                            $file->name = $file_name;
                Severity: Minor
                Found in class/UploadHandler.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 generate_response has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function generate_response($content, $print_response = true)
                    {
                        if ($print_response) {
                            $json     = json_encode($content);
                            $redirect = isset($_REQUEST['redirect']) ? stripslashes($_REQUEST['redirect']) : null;
                Severity: Minor
                Found in class/UploadHandler.php - About 55 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

                Method handle_file_upload has 7 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                        $uploaded_file,
                        $name,
                        $size,
                        $type,
                        $error,
                Severity: Major
                Found in class/UploadHandler.php - About 50 mins to fix

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

                      protected function download()
                      {
                          if (!$this->options['download_via_php']) {
                              $this->header('HTTP/1.1 403 Forbidden');
                  
                  
                  Severity: Minor
                  Found in class/UploadHandler.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 orient_image has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                      protected function orient_image($file_path)
                      {
                          if (!function_exists('exif_read_data')) {
                              return false;
                          }
                  Severity: Minor
                  Found in class/UploadHandler.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 class/UploadHandler.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return true;
                    Severity: Major
                    Found in class/UploadHandler.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return $success;
                      Severity: Major
                      Found in class/UploadHandler.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return false;
                        Severity: Major
                        Found in class/UploadHandler.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return false;
                          Severity: Major
                          Found in class/UploadHandler.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return false;
                            Severity: Major
                            Found in class/UploadHandler.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return false;
                              Severity: Major
                              Found in class/UploadHandler.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return false;
                                Severity: Major
                                Found in class/UploadHandler.php - About 30 mins to fix

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

                                      public function post($print_response = true)
                                      {
                                          if (isset($_REQUEST['_method']) && 'DELETE' === $_REQUEST['_method']) {
                                              return $this->delete($print_response);
                                          }
                                  Severity: Minor
                                  Found in class/UploadHandler.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

                                  There are no issues that match your filters.

                                  Category
                                  Status