gboudreau/Greyhole

View on GitHub
includes/Tasks/FsckTask.php

Summary

Maintainability
F
2 wks
Test Coverage

Function gh_fsck_file has a Cognitive Complexity of 489 (exceeds 5 allowed). Consider refactoring.
Open

    public function gh_fsck_file($path, $filename, $file_type, $source, $share, $storage_path = FALSE, $num_retries = 1) {
        $landing_zone = get_share_landing_zone($share);
        if($storage_path === FALSE) {
            $file_path = trim(mb_substr($path, mb_strlen($landing_zone)+1), '/');
        }else{
Severity: Minor
Found in includes/Tasks/FsckTask.php - About 1 wk 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 gh_fsck_file has 440 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function gh_fsck_file($path, $filename, $file_type, $source, $share, $storage_path = FALSE, $num_retries = 1) {
        $landing_zone = get_share_landing_zone($share);
        if($storage_path === FALSE) {
            $file_path = trim(mb_substr($path, mb_strlen($landing_zone)+1), '/');
        }else{
Severity: Major
Found in includes/Tasks/FsckTask.php - About 2 days to fix

    File FsckTask.php has 710 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /*
    Copyright 2009-2020 Guillaume Boudreau
    
    This file is part of Greyhole.
    Severity: Major
    Found in includes/Tasks/FsckTask.php - About 1 day to fix

      Function execute has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
      Open

          public function execute() {
              $new_conf_hash = static::get_conf_hash();
              if ($this->has_option(OPTION_IF_CONF_CHANGED)) {
                  // Let's check if the conf file changed since the last fsck
      
      
      Severity: Minor
      Found in includes/Tasks/FsckTask.php - About 1 day 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 gh_fsck has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
      Open

          public function gh_fsck($path, $share, $storage_path = FALSE) {
              $path = clean_dir($path);
              Log::debug("Entering $path");
              $this->fsck_report->count(FSCK_COUNT_LZ_DIRS);
      
      
      Severity: Minor
      Found in includes/Tasks/FsckTask.php - About 7 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 execute has 101 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function execute() {
              $new_conf_hash = static::get_conf_hash();
              if ($this->has_option(OPTION_IF_CONF_CHANGED)) {
                  // Let's check if the conf file changed since the last fsck
      
      
      Severity: Major
      Found in includes/Tasks/FsckTask.php - About 4 hrs to fix

        Method gh_fsck has 56 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function gh_fsck($path, $share, $storage_path = FALSE) {
                $path = clean_dir($path);
                Log::debug("Entering $path");
                $this->fsck_report->count(FSCK_COUNT_LZ_DIRS);
        
        
        Severity: Major
        Found in includes/Tasks/FsckTask.php - About 2 hrs to fix

          Function gh_fsck_metastore has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              public function gh_fsck_metastore($root, $path, $share) {
                  if (!is_dir("$root$path")) {
                      // Try NFC form [http://en.wikipedia.org/wiki/Unicode_equivalence#Normalization]
                      $root = normalize_utf8_characters($root);
                      $path = normalize_utf8_characters($path);
          Severity: Minor
          Found in includes/Tasks/FsckTask.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 gh_fsck_metastore has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function gh_fsck_metastore($root, $path, $share) {
                  if (!is_dir("$root$path")) {
                      // Try NFC form [http://en.wikipedia.org/wiki/Unicode_equivalence#Normalization]
                      $root = normalize_utf8_characters($root);
                      $path = normalize_utf8_characters($path);
          Severity: Minor
          Found in includes/Tasks/FsckTask.php - About 1 hr to fix

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

                public function gh_fsck_file($path, $filename, $file_type, $source, $share, $storage_path = FALSE, $num_retries = 1) {
            Severity: Major
            Found in includes/Tasks/FsckTask.php - About 50 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                          while ($count_md5 > 500) {
                                              Log::debug("MD5 tasks pending: $count_md5");
                                              $query = "SELECT id, action, share, full_path, additional_info, complete FROM tasks WHERE complete = 'yes' AND action = 'md5' ORDER BY id LIMIT 1";
                                              $task = DB::getFirst($query);
                                              if ($task) {
              Severity: Major
              Found in includes/Tasks/FsckTask.php - About 45 mins to fix

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

                    public function gh_fsck_reset_du($share, $full_path=null) {
                        if (!$this->has_option(OPTION_DU)) {
                            $this->additional_info .= '|' . OPTION_DU;
                        }
                        $params = array('share' => $share);
                Severity: Minor
                Found in includes/Tasks/FsckTask.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 deeply nested control flow statements.
                Open

                                            if (gh_is_file_locked($key) !== FALSE) {
                                                Log::debug("    File copy is locked. Won't remove it.");
                                                continue;
                                            }
                Severity: Major
                Found in includes/Tasks/FsckTask.php - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                                  if (!$expected_md5) {
                                                      Log::debug("    MD5 not found in 'checksum' table ($share/$file_path/$filename). Will calculate it from the source file.");
                                                      $output = exec("md5sum " . escapeshellarg($original_file_path));
                                                      $output = explode(' ', $output);
                                                      $expected_md5 = $output[0];
                  Severity: Major
                  Found in includes/Tasks/FsckTask.php - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                                if (isset($file_metafiles[$key])) {
                                                    unset($file_metafiles[$key]);
                                                }
                    Severity: Major
                    Found in includes/Tasks/FsckTask.php - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                                      if (empty($file_path)) {
                                                          $expected_md5 = DB::getFirstValue($q, ['share' => $share, 'full_path' => $filename]);
                                                      }
                      Severity: Major
                      Found in includes/Tasks/FsckTask.php - About 45 mins to fix

                        Method update_symlink has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            private function update_symlink($target, $symlink, $share, $file_path, $filename) {
                        Severity: Minor
                        Found in includes/Tasks/FsckTask.php - About 35 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return;
                          Severity: Major
                          Found in includes/Tasks/FsckTask.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                return;
                            Severity: Major
                            Found in includes/Tasks/FsckTask.php - About 30 mins to fix

                              There are no issues that match your filters.

                              Category
                              Status