gboudreau/Greyhole

View on GitHub
includes/StoragePool.php

Summary

Maintainability
F
1 wk
Test Coverage

Function choose_target_drives has a Cognitive Complexity of 164 (exceeds 5 allowed). Consider refactoring.
Open

    public static function choose_target_drives($filesize_kb, $include_full_drives, $share, $path, $log_prefix = '', &$is_sticky = NULL) {
        global $last_OOS_notification;

        foreach (SharesConfig::get($share, CONFIG_DRIVE_SELECTION_ALGORITHM) as $ds) {
            $algo = $ds->selection_algorithm;
Severity: Minor
Found in includes/StoragePool.php - About 3 days 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 check_drives has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring.
Open

    public static function check_drives() {
        Log::setAction(ACTION_CHECK_POOL);

        // If last 'df' ran less than 10s ago, all the drives are already awake; no harm checking them at this time.
        global $last_df_time;
Severity: Minor
Found in includes/StoragePool.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

File StoragePool.php has 560 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/StoragePool.php - About 1 day to fix

    Method choose_target_drives has 210 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function choose_target_drives($filesize_kb, $include_full_drives, $share, $path, $log_prefix = '', &$is_sticky = NULL) {
            global $last_OOS_notification;
    
            foreach (SharesConfig::get($share, CONFIG_DRIVE_SELECTION_ALGORITHM) as $ds) {
                $algo = $ds->selection_algorithm;
    Severity: Major
    Found in includes/StoragePool.php - About 1 day to fix

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

          public static function get_free_space($for_sp_drive) {
              if (time() > StoragePool::$last_df_time + Config::get(CONFIG_DF_CACHE_TIME)) {
                  $dfs = [];
                  exec(ConfigHelper::$df_command, $responses);
                  $responses_arr = array();
      Severity: Minor
      Found in includes/StoragePool.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

      Method check_drives has 116 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function check_drives() {
              Log::setAction(ACTION_CHECK_POOL);
      
              // If last 'df' ran less than 10s ago, all the drives are already awake; no harm checking them at this time.
              global $last_df_time;
      Severity: Major
      Found in includes/StoragePool.php - About 4 hrs to fix

        Function get_file_copies_inodes has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function get_file_copies_inodes($share, $file_path, $filename, &$file_metafiles, $one_is_enough = FALSE) {
                $file_copies_inodes = [];
        
                foreach (Config::storagePoolDrives() as $sp_drive) {
                    $clean_full_path = clean_dir("$sp_drive/$share/$file_path/$filename");
        Severity: Minor
        Found in includes/StoragePool.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 is_pool_drive has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function is_pool_drive($sp_drive) {
                global $going_drive;
                if (isset($going_drive) && $sp_drive == $going_drive) {
                    return FALSE;
                }
        Severity: Minor
        Found in includes/StoragePool.php - About 3 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 get_free_space has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function get_free_space($for_sp_drive) {
                if (time() > StoragePool::$last_df_time + Config::get(CONFIG_DF_CACHE_TIME)) {
                    $dfs = [];
                    exec(ConfigHelper::$df_command, $responses);
                    $responses_arr = array();
        Severity: Minor
        Found in includes/StoragePool.php - About 1 hr to fix

          Method get_file_copies_inodes has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function get_file_copies_inodes($share, $file_path, $filename, &$file_metafiles, $one_is_enough = FALSE) {
                  $file_copies_inodes = [];
          
                  foreach (Config::storagePoolDrives() as $sp_drive) {
                      $clean_full_path = clean_dir("$sp_drive/$share/$file_path/$filename");
          Severity: Minor
          Found in includes/StoragePool.php - About 1 hr to fix

            Method is_pool_drive has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function is_pool_drive($sp_drive) {
                    global $going_drive;
                    if (isset($going_drive) && $sp_drive == $going_drive) {
                        return FALSE;
                    }
            Severity: Minor
            Found in includes/StoragePool.php - About 1 hr to fix

              Avoid deeply nested control flow statements.
              Open

                                                  if ($needle == '') {
                                                      $needle = '/';
                                                  }
              Severity: Major
              Found in includes/StoragePool.php - About 45 mins to fix

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

                    public static function choose_target_drives($filesize_kb, $include_full_drives, $share, $path, $log_prefix = '', &$is_sticky = NULL) {
                Severity: Minor
                Found in includes/StoragePool.php - About 45 mins to fix

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

                      public static function get_file_copies_inodes($share, $file_path, $filename, &$file_metafiles, $one_is_enough = FALSE) {
                  Severity: Minor
                  Found in includes/StoragePool.php - About 35 mins to fix

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

                                if (!empty($last_resort_sorted_target_drives)) {
                                    $log = $log_prefix . "Drives with enough free space, but no available space: ";
                                    foreach ($last_resort_sorted_target_drives as $sp_drive => $space) {
                                        /** @noinspection PhpUndefinedVariableInspection */
                                        $log .= "$sp_drive (" . bytes_to_human($space*1024, FALSE) . " " . ($algo == 'most_available_space' ? 'avail' : 'used') . ") - ";
                    Severity: Major
                    Found in includes/StoragePool.php and 1 other location - About 1 hr to fix
                    includes/StoragePool.php on lines 503..510

                    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 115.

                    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

                                if (!empty($sorted_target_drives)) {
                                    $log = $log_prefix . "Drives with available space: ";
                                    foreach ($sorted_target_drives as $sp_drive => $space) {
                                        /** @noinspection PhpUndefinedVariableInspection */
                                        $log .= "$sp_drive (" . bytes_to_human($space*1024, FALSE) . " " . ($algo == 'most_available_space' ? 'avail' : 'used') . ") - ";
                    Severity: Major
                    Found in includes/StoragePool.php and 1 other location - About 1 hr to fix
                    includes/StoragePool.php on lines 511..518

                    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 115.

                    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

                    There are no issues that match your filters.

                    Category
                    Status