gboudreau/Greyhole

View on GitHub

Showing 371 of 371 total issues

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

    Function create_file_copies_from_metafiles has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function create_file_copies_from_metafiles($metafiles, $share, $full_path, $source_file, $missing_only = FALSE) {
            $landing_zone = get_share_landing_zone($share);
    
            list($path, $filename) = explode_full_path($full_path);
    
    
    Severity: Minor
    Found in includes/StorageFile.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_mkdir has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
    Open

    function gh_mkdir($directory, $original_directory, $dir_permissions = NULL) {
        $directory = clean_dir($directory);
        $original_directory = clean_dir($original_directory);
        if (is_dir($directory)) {
            if (empty($dir_permissions)) {
    Severity: Minor
    Found in includes/SystemHelper.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 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

    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

    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

      Method parse_samba_spool has 197 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function parse_samba_spool() {
              Log::setAction(ACTION_READ_SAMBA_POOL);
      
              $db_spool = DBSpool::getInstance();
      
      
      Severity: Major
      Found in includes/SambaSpool.php - About 7 hrs to fix

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

        function trashmanDelete(btn) {
            let $row = $(btn).closest('tr');
            let folder = $('#trashman-current-dir').val() + '/' + $row.data('path');
            folder = folder.substring(2);
        
        
        Severity: Major
        Found in web-app/scripts.js and 1 other location - About 7 hrs to fix
        web-app/scripts.js on lines 177..188

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

        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

        function trashmanRestore(btn) {
            let $row = $(btn).closest('tr');
            let folder = $('#trashman-current-dir').val() + '/' + $row.data('path');
            folder = folder.substring(2);
        
        
        Severity: Major
        Found in web-app/scripts.js and 1 other location - About 7 hrs to fix
        web-app/scripts.js on lines 155..166

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

        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

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

            public function execute() {
                $share = $this->share;
                $full_path = $this->full_path;
        
                $landing_zone = get_share_landing_zone($share);
        Severity: Minor
        Found in includes/Tasks/UnlinkTask.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

        File DB.php has 472 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        <?php
        /*
        Copyright 2014-2020 Guillaume Boudreau
        
        This file is part of Greyhole.
        Severity: Minor
        Found in includes/DB.php - About 7 hrs to fix

          Function next has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
          Open

              #[\ReturnTypeWillChange]
              public function next() {
                  $this->metafiles = array();
                  while (count($this->directory_stack) > 0 && $this->directory_stack !== NULL) {
                      $dir = array_pop($this->directory_stack);
          Severity: Minor
          Found in includes/Metastores.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

          Function create_file_copy has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
          Open

              public static function create_file_copy($source_file, &$destination_file, $expected_md5 = NULL, &$error = NULL) {
                  if (gh_is_file($source_file) && $source_file == $destination_file) {
                      Log::debug("  Destination $destination_file is the same as the source. Nothing to do here; this file copy is ready!");
                      return TRUE;
                  }
          Severity: Minor
          Found in includes/StorageFile.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

          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 gh_check_md5 has 173 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function gh_check_md5($task) {
                  /** @var $task AbstractTask */
                  $share_options = SharesConfig::getConfigForShare($task->share);
          
                  $query = "SELECT complete, COUNT(*) AS num, GROUP_CONCAT(id) AS ids FROM tasks WHERE action = 'md5' AND share = :share AND full_path = :full_path GROUP BY complete ORDER BY complete";
          Severity: Major
          Found in includes/Tasks/Md5Task.php - About 6 hrs to fix

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

            foreach ($output as $line) {
                if (preg_match('/\s*\[(.+)]\s*$/', $line, $re)) {
                    $share_name = $re[1];
                    if (array_contains(ConfigHelper::$trash_share_names, $share_name)) {
                        $share_options = SharesConfig::getConfigForShare(CONFIG_TRASH_SHARE);
            Severity: Major
            Found in web-app/views/samba_shares.php and 1 other location - About 6 hrs to fix
            web-app/views/trash.php on lines 327..346

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

            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

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

                foreach ($output as $line) {
                    if (preg_match('/\s*\[(.+)]\s*$/', $line, $re)) {
                        $share_name = $re[1];
                        if (array_contains(ConfigHelper::$trash_share_names, $share_name)) {
                            $share_options = SharesConfig::getConfigForShare(CONFIG_TRASH_SHARE);
            Severity: Major
            Found in web-app/views/trash.php and 1 other location - About 6 hrs to fix
            web-app/views/samba_shares.php on lines 46..65

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

            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

            Method get_config_html has 161 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function get_config_html($config, $current_value = NULL, $fixed_width_label = TRUE) {
                $config = (object) $config;
                $html = '';
                if ($config->type == 'group') {
                    $html .= "<div class='input_group mt-4'>";
            Severity: Major
            Found in web-app/functions.inc.php - About 6 hrs to fix

              Function create_file_copies has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function create_file_copies($source_file, &$metafiles) {
                      $copy_results = [];
              
                      $copy_source = is_link($source_file) ? readlink($source_file) : $source_file;
                      $source_size = gh_filesize($copy_source);
              Severity: Minor
              Found in includes/StorageFile.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 _log has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static function _log($local_log_level, $text, $event_code) {
                      if (self::$action == 'test-config' || self::$action == ACTION_CP) {
                          $greyhole_log_file = NULL;
                          $use_syslog = FALSE;
                          if (self::$action == ACTION_CP && $local_log_level > self::$level) {
              Severity: Minor
              Found in includes/Log.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

              Severity
              Category
              Status
              Source
              Language