bcit-ci/CodeIgniter

View on GitHub
system/database/DB_driver.php

Summary

Maintainability
F
1 wk
Test Coverage

File DB_driver.php has 842 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP
Severity: Major
Found in system/database/DB_driver.php - About 2 days to fix

    CI_DB_driver has 56 functions (exceeds 20 allowed). Consider refactoring.
    Open

    abstract class CI_DB_driver {
    
        /**
         * Data Source Name / Connect string
         *
    Severity: Major
    Found in system/database/DB_driver.php - About 1 day to fix

      Function protect_identifiers has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring.
      Open

          public function protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
          {
              if ( ! is_bool($protect_identifiers))
              {
                  $protect_identifiers = $this->_protect_identifiers;
      Severity: Minor
      Found in system/database/DB_driver.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 query has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
      Open

          public function query($sql, $binds = FALSE, $return_object = NULL)
          {
              if ($sql === '')
              {
                  log_message('error', 'Invalid query: '.$sql);
      Severity: Minor
      Found in system/database/DB_driver.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 protect_identifiers has 106 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function protect_identifiers($item, $prefix_single = FALSE, $protect_identifiers = NULL, $field_exists = TRUE)
          {
              if ( ! is_bool($protect_identifiers))
              {
                  $protect_identifiers = $this->_protect_identifiers;
      Severity: Major
      Found in system/database/DB_driver.php - About 4 hrs to fix

        Method query has 85 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function query($sql, $binds = FALSE, $return_object = NULL)
            {
                if ($sql === '')
                {
                    log_message('error', 'Invalid query: '.$sql);
        Severity: Major
        Found in system/database/DB_driver.php - About 3 hrs to fix

          Function initialize has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

              public function initialize()
              {
                  /* If an established connection is available, then there's
                   * no need to connect and select the database.
                   *
          Severity: Minor
          Found in system/database/DB_driver.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

          Method compile_binds has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function compile_binds($sql, $binds)
              {
                  if (empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE)
                  {
                      return $sql;
          Severity: Minor
          Found in system/database/DB_driver.php - About 1 hr to fix

            Method escape_identifiers has 43 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function escape_identifiers($item, $split = TRUE)
                {
                    if ($this->_escape_char === '' OR empty($item) OR in_array($item, $this->_reserved_identifiers))
                    {
                        return $item;
            Severity: Minor
            Found in system/database/DB_driver.php - About 1 hr to fix

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

                  public function display_error($error = '', $swap = '', $native = FALSE)
                  {
                      $LANG =& load_class('Lang', 'core');
                      $LANG->load('db');
              
              
              Severity: Minor
              Found in system/database/DB_driver.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 escape_identifiers has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function escape_identifiers($item, $split = TRUE)
                  {
                      if ($this->_escape_char === '' OR empty($item) OR in_array($item, $this->_reserved_identifiers))
                      {
                          return $item;
              Severity: Minor
              Found in system/database/DB_driver.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 display_error has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function display_error($error = '', $swap = '', $native = FALSE)
                  {
                      $LANG =& load_class('Lang', 'core');
                      $LANG->load('db');
              
              
              Severity: Minor
              Found in system/database/DB_driver.php - About 1 hr to fix

                Method list_tables has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function list_tables($constrain_by_prefix = FALSE)
                    {
                        // Is there a cached result?
                        if (isset($this->data_cache['table_names']))
                        {
                Severity: Minor
                Found in system/database/DB_driver.php - About 1 hr to fix

                  Function list_tables has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function list_tables($constrain_by_prefix = FALSE)
                      {
                          // Is there a cached result?
                          if (isset($this->data_cache['table_names']))
                          {
                  Severity: Minor
                  Found in system/database/DB_driver.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 initialize has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function initialize()
                      {
                          /* If an established connection is available, then there's
                           * no need to connect and select the database.
                           *
                  Severity: Minor
                  Found in system/database/DB_driver.php - About 1 hr to fix

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

                        public function list_fields($table)
                        {
                            if (FALSE === ($sql = $this->_list_columns($table)))
                            {
                                return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
                    Severity: Minor
                    Found in system/database/DB_driver.php - About 1 hr to fix

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

                          public function list_fields($table)
                          {
                              if (FALSE === ($sql = $this->_list_columns($table)))
                              {
                                  return ($this->db_debug) ? $this->display_error('db_unsupported_function') : FALSE;
                      Severity: Minor
                      Found in system/database/DB_driver.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 compile_binds has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public function compile_binds($sql, $binds)
                          {
                              if (empty($this->bind_marker) OR strpos($sql, $this->bind_marker) === FALSE)
                              {
                                  return $sql;
                      Severity: Minor
                      Found in system/database/DB_driver.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

                      Avoid too many return statements within this method.
                      Open

                                  return TRUE;
                      Severity: Major
                      Found in system/database/DB_driver.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return $RES;
                        Severity: Major
                        Found in system/database/DB_driver.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return preg_replace('#'.$preg_ec[0].'?([^'.$preg_ec[1].$dot.']+)'.$preg_ec[1].'?(\.)?#i', $preg_ec[2].'$1'.$preg_ec[3].'$2', $item);
                          Severity: Major
                          Found in system/database/DB_driver.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                    return $item.$alias;
                            Severity: Major
                            Found in system/database/DB_driver.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return $str;
                              Severity: Major
                              Found in system/database/DB_driver.php - About 30 mins to fix

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

                                        if ($c = preg_match_all("/'[^']*'|\"[^\"]*\"/i", $sql, $matches))
                                        {
                                            $c = preg_match_all('/'.preg_quote($this->bind_marker, '/').'/i',
                                                str_replace($matches[0],
                                                    str_replace($this->bind_marker, str_repeat(' ', $ml), $matches[0]),
                                Severity: Major
                                Found in system/database/DB_driver.php and 1 other location - About 5 hrs to fix
                                system/database/drivers/odbc/odbc_driver.php on lines 176..193

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

                                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