gboudreau/Greyhole

View on GitHub
includes/DB.php

Summary

Maintainability
F
3 days
Test Coverage

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

    DB has 36 functions (exceeds 20 allowed). Consider refactoring.
    Open

    final class DB {
    
        /** @var stdClass */
        protected static $options; // connection options
        /** @var PDO */
    Severity: Minor
    Found in includes/DB.php - About 4 hrs to fix

      Method migrate_10_utf8 has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function migrate_10_utf8() {
              $q = "SHOW INDEX FROM du_stats WHERE key_name = 'uniqness' AND column_name = 'full_path'";
              $index_def = DB::getFirst($q);
              if ($index_def->Sub_part > 269) {
                  $q = "ALTER TABLE du_stats DROP INDEX uniqness";
      Severity: Major
      Found in includes/DB.php - About 2 hrs to fix

        Function migrate_10_utf8 has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            private static function migrate_10_utf8() {
                $q = "SHOW INDEX FROM du_stats WHERE key_name = 'uniqness' AND column_name = 'full_path'";
                $index_def = DB::getFirst($q);
                if ($index_def->Sub_part > 269) {
                    $q = "ALTER TABLE du_stats DROP INDEX uniqness";
        Severity: Minor
        Found in includes/DB.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 connect has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function connect($retry_until_successful=FALSE, $throw_exception_on_error=FALSE, $timeout = 10) {
                $connect_string = 'mysql:host=' . self::$options->host . ';dbname=' . self::$options->name . ';charset=utf8mb4';
        
                try {
                    self::$handle = @new PDO($connect_string, self::$options->user, self::$options->pass, array(PDO::ATTR_TIMEOUT => $timeout, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
        Severity: Minor
        Found in includes/DB.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 migrate has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static function migrate() {
                $db_version = (int) Settings::get('db_version');
                if ($db_version < 11) {
                    DB::migrate_1_frozen_thaw();
                    DB::migrate_2_idle();
        Severity: Minor
        Found in includes/DB.php - About 1 hr to fix

          Method connect has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function connect($retry_until_successful=FALSE, $throw_exception_on_error=FALSE, $timeout = 10) {
                  $connect_string = 'mysql:host=' . self::$options->host . ';dbname=' . self::$options->name . ';charset=utf8mb4';
          
                  try {
                      self::$handle = @new PDO($connect_string, self::$options->user, self::$options->pass, array(PDO::ATTR_TIMEOUT => $timeout, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
          Severity: Minor
          Found in includes/DB.php - About 1 hr to fix

            Method migrate_18_full_path_utf8mb4 has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private static function migrate_18_full_path_utf8mb4() {
                    $q = "ALTER TABLE `checksums` CHANGE `full_path` `full_path` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL";
                    DB::execute($q);
            
                    $query = "DESCRIBE tasks";
            Severity: Minor
            Found in includes/DB.php - About 1 hr to fix

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

                  private static function migrate_6_md5_worker_indexes() {
                      $query = "SHOW INDEX FROM tasks WHERE Key_name = 'md5_worker'";
                      $row = DB::getFirst($query);
                      if ($row === FALSE) {
                          // migrate
              Severity: Minor
              Found in includes/DB.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 execute has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function execute($q, $args = array(), $attempt_repair=TRUE) {
                      $stmt = self::$handle->prepare($q);
                      foreach ($args as $key => $value) {
                          $stmt->bindValue(":$key", $value);
                      }
              Severity: Minor
              Found in includes/DB.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 migrate has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static function migrate() {
                      $db_version = (int) Settings::get('db_version');
                      if ($db_version < 11) {
                          DB::migrate_1_frozen_thaw();
                          DB::migrate_2_idle();
              Severity: Minor
              Found in includes/DB.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

              Function migrate_18_full_path_utf8mb4 has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static function migrate_18_full_path_utf8mb4() {
                      $q = "ALTER TABLE `checksums` CHANGE `full_path` `full_path` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL";
                      DB::execute($q);
              
                      $query = "DESCRIBE tasks";
              Severity: Minor
              Found in includes/DB.php - About 35 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 migrate_9_complete_writen has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static function migrate_9_complete_writen() {
                      $query = "DESCRIBE tasks";
                      $rows = DB::getAll($query);
                      foreach ($rows as $row) {
                          if ($row->Field == 'complete') {
              Severity: Minor
              Found in includes/DB.php - About 35 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 migrate_3_larger_settings has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static function migrate_3_larger_settings() {
                      $query = "DESCRIBE settings";
                      $rows = DB::getAll($query);
                      foreach ($rows as $row) {
                          if ($row->Field == 'value') {
              Severity: Minor
              Found in includes/DB.php - About 35 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