gboudreau/Greyhole

View on GitHub
includes/Tasks/BalanceTask.php

Summary

Maintainability
F
3 days
Test Coverage

Function balance_file has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
Open

    private function balance_file($file, $share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, &$file_too_large_warnings) {
        $num_total_drives = count($pool_drives_avail_space);
        $current_avail_space = $pool_drives_avail_space[$source_drive];
        $target_avail_space = array_sum($pool_drives_avail_space) / count($pool_drives_avail_space);
        $delta_needed = $target_avail_space - $current_avail_space;
Severity: Minor
Found in includes/Tasks/BalanceTask.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

Method balance_file has 119 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function balance_file($file, $share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, &$file_too_large_warnings) {
        $num_total_drives = count($pool_drives_avail_space);
        $current_avail_space = $pool_drives_avail_space[$source_drive];
        $target_avail_space = array_sum($pool_drives_avail_space) / count($pool_drives_avail_space);
        $delta_needed = $target_avail_space - $current_avail_space;
Severity: Major
Found in includes/Tasks/BalanceTask.php - About 4 hrs to fix

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

        public function execute() {
            Log::info("Starting available space balancing");
    
            // Start with shares that have sticky files, so that subsequent shares will be used to try to balance what moving files into stick_into drives could debalance...
            // Then start with the shares for which we keep the most # copies;
    Severity: Minor
    Found in includes/Tasks/BalanceTask.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

    File BalanceTask.php has 254 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /*
    Copyright 2009-2020 Guillaume Boudreau
    
    This file is part of Greyhole.
    Severity: Minor
    Found in includes/Tasks/BalanceTask.php - About 2 hrs to fix

      Function balance_share has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          private function balance_share($share, $share_options, $min_file_size) {
              Log::debug("├┐ Balancing share: $share ({$min_file_size}MB or + files)");
      
              /** @var $drives_selectors PoolDriveSelector[] */
              $drives_selectors = Config::get(CONFIG_DRIVE_SELECTION_ALGORITHM);
      Severity: Minor
      Found in includes/Tasks/BalanceTask.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 execute has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function execute() {
              Log::info("Starting available space balancing");
      
              // Start with shares that have sticky files, so that subsequent shares will be used to try to balance what moving files into stick_into drives could debalance...
              // Then start with the shares for which we keep the most # copies;
      Severity: Minor
      Found in includes/Tasks/BalanceTask.php - About 1 hr to fix

        Method balance_share has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function balance_share($share, $share_options, $min_file_size) {
                Log::debug("├┐ Balancing share: $share ({$min_file_size}MB or + files)");
        
                /** @var $drives_selectors PoolDriveSelector[] */
                $drives_selectors = Config::get(CONFIG_DRIVE_SELECTION_ALGORITHM);
        Severity: Minor
        Found in includes/Tasks/BalanceTask.php - About 1 hr to fix

          Method balance_drive has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function balance_drive($share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, $min_file_size) {
                  $current_avail_space = $pool_drives_avail_space[$source_drive];
                  $target_avail_space = array_sum($pool_drives_avail_space) / count($pool_drives_avail_space);
                  $delta_needed = $target_avail_space - $current_avail_space;
                  if ($delta_needed <= 10*1024 || $delta_needed < $min_file_size*1024) {
          Severity: Minor
          Found in includes/Tasks/BalanceTask.php - About 1 hr to fix

            Function balance_drive has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                private function balance_drive($share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, $min_file_size) {
                    $current_avail_space = $pool_drives_avail_space[$source_drive];
                    $target_avail_space = array_sum($pool_drives_avail_space) / count($pool_drives_avail_space);
                    $delta_needed = $target_avail_space - $current_avail_space;
                    if ($delta_needed <= 10*1024 || $delta_needed < $min_file_size*1024) {
            Severity: Minor
            Found in includes/Tasks/BalanceTask.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 balance_file has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                private function balance_file($file, $share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, &$file_too_large_warnings) {
            Severity: Major
            Found in includes/Tasks/BalanceTask.php - About 50 mins to fix

              Method balance_drive has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  private function balance_drive($share, $share_options, $source_drive, &$pool_drives_avail_space, $balance_direction_asc, $min_file_size) {
              Severity: Minor
              Found in includes/Tasks/BalanceTask.php - About 45 mins to fix

                Avoid too many return statements within this method.
                Open

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

                  Avoid too many return statements within this method.
                  Open

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

                    Avoid too many return statements within this method.
                    Open

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

                      Avoid too many return statements within this method.
                      Open

                                      return $this->execute();
                      Severity: Major
                      Found in includes/Tasks/BalanceTask.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

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

                          Avoid too many return statements within this method.
                          Open

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

                            Avoid too many return statements within this method.
                            Open

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

                              Avoid too many return statements within this method.
                              Open

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

                                Avoid too many return statements within this method.
                                Open

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

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

                                      private static function is_share_sticky($share_name) {
                                          $sticky_files = Config::get(CONFIG_STICKY_FILES);
                                          if (!empty($sticky_files)) {
                                              foreach ($sticky_files as $share_dir => $stick_into) {
                                                  if (string_starts_with($share_dir, $share_name)) {
                                  Severity: Minor
                                  Found in includes/Tasks/BalanceTask.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