gboudreau/Greyhole

View on GitHub
includes/Metastores.php

Summary

Maintainability
F
1 wk
Test Coverage

Function get_metafiles_for_file has a Cognitive Complexity of 68 (exceeds 5 allowed). Consider refactoring.
Open

    public static function get_metafiles_for_file($share, $path, $filename=NULL, $load_nok_metafiles=FALSE, $quiet=FALSE, $check_symlink=TRUE) {
        if (!$quiet) {
            Log::debug("Loading metafiles for " . clean_dir($share . (!empty($path) ? "/$path" : "") . "/$filename") . ' ...');
        }
        $metafiles_data_file = static::get_metafile_data_filename($share, $path, $filename);
Severity: Minor
Found in includes/Metastores.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 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

File Metastores.php has 425 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/Metastores.php - About 6 hrs to fix

    Function save_metafiles has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function save_metafiles($share, $path, $filename, $metafiles) {
            if (count($metafiles) == 0) {
                static::remove_metafiles($share, $path, $filename);
                return;
            }
    Severity: Minor
    Found in includes/Metastores.php - About 5 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_metafiles has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function create_metafiles($share, $full_path, $num_copies_required, $filesize, $metafiles=[]) {
            $found_link_metafile = FALSE;
    
            list($path, ) = explode_full_path($full_path);
    
    
    Severity: Minor
    Found in includes/Metastores.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 choose_metastores_backups has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function choose_metastores_backups($try_restore=TRUE) {
            $num_metastore_backups_needed = 2;
            if (count(Config::storagePoolDrives()) < 2) {
                Config::set(CONFIG_METASTORE_BACKUPS, array());
                return;
    Severity: Minor
    Found in includes/Metastores.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_metafiles_for_file has 70 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function get_metafiles_for_file($share, $path, $filename=NULL, $load_nok_metafiles=FALSE, $quiet=FALSE, $check_symlink=TRUE) {
            if (!$quiet) {
                Log::debug("Loading metafiles for " . clean_dir($share . (!empty($path) ? "/$path" : "") . "/$filename") . ' ...');
            }
            $metafiles_data_file = static::get_metafile_data_filename($share, $path, $filename);
    Severity: Major
    Found in includes/Metastores.php - About 2 hrs to fix

      Method create_metafiles has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function create_metafiles($share, $full_path, $num_copies_required, $filesize, $metafiles=[]) {
              $found_link_metafile = FALSE;
      
              list($path, ) = explode_full_path($full_path);
      
      
      Severity: Major
      Found in includes/Metastores.php - About 2 hrs to fix

        Method save_metafiles has 53 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function save_metafiles($share, $path, $filename, $metafiles) {
                if (count($metafiles) == 0) {
                    static::remove_metafiles($share, $path, $filename);
                    return;
                }
        Severity: Major
        Found in includes/Metastores.php - About 2 hrs to fix

          Method choose_metastores_backups has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function choose_metastores_backups($try_restore=TRUE) {
                  $num_metastore_backups_needed = 2;
                  if (count(Config::storagePoolDrives()) < 2) {
                      Config::set(CONFIG_METASTORE_BACKUPS, array());
                      return;
          Severity: Minor
          Found in includes/Metastores.php - About 1 hr to fix

            Method next has 45 lines of code (exceeds 25 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 1 hr to fix

              Function get_metastores has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function get_metastores($use_cache=TRUE) {
                      if (!$use_cache) {
                          static::$metastores = [];
                      }
                      if (empty(static::$metastores)) {
              Severity: Minor
              Found in includes/Metastores.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 get_metafile_data_filenames has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function get_metafile_data_filenames($share, $path, $filename, $first_only=FALSE) {
                      $filenames = array();
              
                      if ($first_only) {
                          $share_file = get_share_landing_zone($share) . "/$path/$filename";
              Severity: Minor
              Found in includes/Metastores.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 get_metafiles has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public static function get_metafiles($share, $path, $filename=NULL, $load_nok_metafiles=FALSE, $quiet=FALSE, $check_symlink=TRUE) {
              Severity: Minor
              Found in includes/Metastores.php - About 45 mins to fix

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

                    public static function get_metafiles_for_file($share, $path, $filename=NULL, $load_nok_metafiles=FALSE, $quiet=FALSE, $check_symlink=TRUE) {
                Severity: Minor
                Found in includes/Metastores.php - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                              if (isset($this->metafiles[$full_filename])) {
                                                  continue;
                                              }
                  Severity: Major
                  Found in includes/Metastores.php - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

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

                      Avoid deeply nested control flow statements.
                      Open

                                                  } else if (empty($metafile->is_linked) && $metafile->path == $share_file_link_to) {
                                                      if (!$quiet) {
                                                          Log::debug('  Changing is_linked to TRUE for ' . $metafile->path);
                                                      }
                                                      $metafile->is_linked = TRUE;
                      Severity: Major
                      Found in includes/Metastores.php - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                        if (!$quiet) {
                                                            Log::debug('  Changing is_linked to FALSE for ' . $metafile->path);
                                                        }
                        Severity: Major
                        Found in includes/Metastores.php - About 45 mins to fix

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

                              public function __construct($share, $path, $load_nok_metafiles=FALSE, $quiet=FALSE, $check_symlink=TRUE) {
                          Severity: Minor
                          Found in includes/Metastores.php - About 35 mins to fix

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

                                public static function create_metafiles($share, $full_path, $num_copies_required, $filesize, $metafiles=[]) {
                            Severity: Minor
                            Found in includes/Metastores.php - About 35 mins to fix

                              There are no issues that match your filters.

                              Category
                              Status