gboudreau/Greyhole

View on GitHub
includes/common.php

Summary

Maintainability
F
5 days
Test Coverage

File common.php has 797 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/*
Copyright 2009-2020 Guillaume Boudreau, Andrew Hopkinson

This file is part of Greyhole.
Severity: Major
Found in includes/common.php - About 1 day to fix

    Function json_pretty_print has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    function json_pretty_print($json) {
        if (defined('JSON_PRETTY_PRINT')) {
            if (is_string($json)) {
                $json = json_decode($json);
            }
    Severity: Minor
    Found in includes/common.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 get_email_body has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

        public function get_email_body($include_trash_size) {
            if (empty($this->end)) {
                $this->end = time();
            }
    
    
    Severity: Minor
    Found in includes/common.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_email_body has 74 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function get_email_body($include_trash_size) {
            if (empty($this->end)) {
                $this->end = time();
            }
    
    
    Severity: Major
    Found in includes/common.php - About 2 hrs to fix

      Method json_pretty_print has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function json_pretty_print($json) {
          if (defined('JSON_PRETTY_PRINT')) {
              if (is_string($json)) {
                  $json = json_decode($json);
              }
      Severity: Major
      Found in includes/common.php - About 2 hrs to fix

        Function get_debug_bt has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

        function get_debug_bt() {
            $bt = '';
            foreach (debug_backtrace() as $d) {
                if ($d['function'] == 'gh_error_handler' || $d['function'] == 'get_debug_bt') { continue; }
                if ($bt != '') {
        Severity: Minor
        Found in includes/common.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

        Function fix_symlinks_on_share has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        function fix_symlinks_on_share($share_name) {
            $share_options = SharesConfig::getConfigForShare($share_name);
            echo "Looking for broken symbolic links in the share '$share_name'...";
            chdir($share_options[CONFIG_LANDING_ZONE]);
            exec("find -L . -type l", $result);
        Severity: Minor
        Found in includes/common.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

        Function gh_wild_mb_strpos has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

        function gh_wild_mb_strpos($haystack, $needle) {
            /** @noinspection PhpSuspiciousNameCombinationInspection */
            $is_wild = string_contains($needle, "*");
            if (!$is_wild) {
                return mb_strpos($haystack, $needle);
        Severity: Minor
        Found in includes/common.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 taskCompleted has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function taskCompleted($task_id, $send_email) {
                $fsck_work_log = static::getFromDisk();
                foreach ($fsck_work_log->tasks as $task) {
                    if ($task->id == $task_id) {
                        $task->status = static::STATUS_COMPLETE;
        Severity: Minor
        Found in includes/common.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_wild_mb_strpos has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function gh_wild_mb_strpos($haystack, $needle) {
            /** @noinspection PhpSuspiciousNameCombinationInspection */
            $is_wild = string_contains($needle, "*");
            if (!$is_wild) {
                return mb_strpos($haystack, $needle);
        Severity: Minor
        Found in includes/common.php - About 1 hr to fix

          Method taskCompleted has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function taskCompleted($task_id, $send_email) {
                  $fsck_work_log = static::getFromDisk();
                  foreach ($fsck_work_log->tasks as $task) {
                      if ($task->id == $task_id) {
                          $task->status = static::STATUS_COMPLETE;
          Severity: Minor
          Found in includes/common.php - About 1 hr to fix

            Method get_debug_bt has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function get_debug_bt() {
                $bt = '';
                foreach (debug_backtrace() as $d) {
                    if ($d['function'] == 'gh_error_handler' || $d['function'] == 'get_debug_bt') { continue; }
                    if ($bt != '') {
            Severity: Minor
            Found in includes/common.php - About 1 hr to fix

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

              function string_starts_with($haystack, $needle) {
                  if (!is_string($haystack) || empty($haystack)) {
                      return FALSE;
                  }
                  if (is_array($needle)) {
              Severity: Minor
              Found in includes/common.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

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

              function string_ends_with($haystack, $needle) {
                  if (!is_string($haystack) || empty($haystack)) {
                      return FALSE;
                  }
                  if (is_array($needle)) {
              Severity: Minor
              Found in includes/common.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

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

                  public static function getHumanReadableReport() {
                      $fsck_work_log = static::getFromDisk();
              
                      if (count($fsck_work_log->tasks) == 1) {
                          $task = first($fsck_work_log->tasks);
              Severity: Minor
              Found in includes/common.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

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

                  public static function get_trash_size_report() {
                      $report = "Trash size:\n";
                      foreach (Config::storagePoolDrives() as $sp_drive) {
                          $trash_path = clean_dir("$sp_drive/.gh_trash");
                          if (is_dir($trash_path)) {
              Severity: Minor
              Found in includes/common.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

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

              function gh_error_handler($errno, $errstr, $errfile, $errline, $errcontext = NULL) {
              Severity: Minor
              Found in includes/common.php - About 35 mins to fix

                Avoid too many return statements within this method.
                Open

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

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

                  function gh_error_handler($errno, $errstr, $errfile, $errline, $errcontext = NULL) {
                      if(!($errno & error_reporting())) {
                          // Ignored (@) warning
                          return TRUE;
                      }
                  Severity: Minor
                  Found in includes/common.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

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

                  function clean_dir($dir) {
                      if (empty($dir)) {
                          return $dir;
                      }
                      if ($dir[0] == '.' && $dir[1] == '/') {
                  Severity: Minor
                  Found in includes/common.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

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

                      private function getBody() {
                          $logfile = "$this->path/$this->filename";
                          if ($this->filename == 'fsck_checksums.log') {
                              return file_get_contents($logfile) . "\nNote: You should manually delete the $logfile file once you're done with it.";
                          } else if ($this->filename == 'fsck_files.log' && file_exists($logfile)) {
                  Severity: Minor
                  Found in includes/common.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

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

                  function bytes_to_human($bytes, $html=TRUE, $iso_units=FALSE) {
                      $units = 'B';
                      if (abs($bytes) > 1024) {
                          $bytes /= 1024;
                          $units = $iso_units ? 'KiB' : 'KB';
                  Severity: Minor
                  Found in includes/common.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