detain/db_abstraction

View on GitHub
src/Mysqli/Db.php

Summary

Maintainability
D
2 days
Test Coverage

Function query has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

    public function query($queryString, $line = '', $file = '')
    {
        /* No empty queries, please, since PHP4 chokes on them. */
        /* The empty query string is passed on from the constructor,
        * when calling the class without a query, e.g. in situations
Severity: Minor
Found in src/Mysqli/Db.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

File Db.php has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * MySQL Related Functionality
 * @author Joe Huss <detain@interserver.net>
 * @copyright 2019
Severity: Minor
Found in src/Mysqli/Db.php - About 3 hrs to fix

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

        public function query($queryString, $line = '', $file = '')
        {
            /* No empty queries, please, since PHP4 chokes on them. */
            /* The empty query string is passed on from the constructor,
            * when calling the class without a query, e.g. in situations
    Severity: Major
    Found in src/Mysqli/Db.php - About 2 hrs to fix

      Db has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class Db extends Generic implements Db_Interface
      {
          /**
           * @var string
           */
      Severity: Minor
      Found in src/Mysqli/Db.php - About 2 hrs to fix

        Function connect has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public function connect($database = '', $host = '', $user = '', $password = '', $port = '')
            {
                /* Handle defaults */
                if ($database == '') {
                    $database = $this->database;
        Severity: Minor
        Found in src/Mysqli/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 connect has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function connect($database = '', $host = '', $user = '', $password = '', $port = '')
            {
                /* Handle defaults */
                if ($database == '') {
                    $database = $this->database;
        Severity: Minor
        Found in src/Mysqli/Db.php - About 1 hr to fix

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

              public function lock($table, $mode = 'write')
              {
                  $this->connect();
                  $query = 'lock tables ';
                  if (is_array($table)) {
          Severity: Minor
          Found in src/Mysqli/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 connect has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              public function connect($database = '', $host = '', $user = '', $password = '', $port = '')
          Severity: Minor
          Found in src/Mysqli/Db.php - About 35 mins to fix

            Remove error control operator '@' on line 257.
            Open

                public function query($queryString, $line = '', $file = '')
                {
                    /* No empty queries, please, since PHP4 chokes on them. */
                    /* The empty query string is passed on from the constructor,
                    * when calling the class without a query, e.g. in situations
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 278.
            Open

                public function query($queryString, $line = '', $file = '')
                {
                    /* No empty queries, please, since PHP4 chokes on them. */
                    /* The empty query string is passed on from the constructor,
                    * when calling the class without a query, e.g. in situations
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 340.
            Open

                public function seek($pos = 0)
                {
                    $status = @mysqli_data_seek($this->queryId, $pos);
                    if ($status) {
                        $this->Row = $pos;
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 133.
            Open

                public function free()
                {
                    if (is_resource($this->queryId)) {
                        @mysqli_free_result($this->queryId);
                    }
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 347.
            Open

                public function seek($pos = 0)
                {
                    $status = @mysqli_data_seek($this->queryId, $pos);
                    if ($status) {
                        $this->Row = $pos;
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 320.
            Open

                public function next_record($resultType = MYSQLI_BOTH)
                {
                    if ($this->queryId === false) {
                        $this->haltmsg('next_record called with no query pending.');
                        return 0;
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 438.
            Open

                public function lock($table, $mode = 'write')
                {
                    $this->connect();
                    $query = 'lock tables ';
                    if (is_array($table)) {
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 489.
            Open

                public function num_fields()
                {
                    return @mysqli_num_fields($this->queryId);
                }
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 246.
            Open

                public function query($queryString, $line = '', $file = '')
                {
                    /* No empty queries, please, since PHP4 chokes on them. */
                    /* The empty query string is passed on from the constructor,
                    * when calling the class without a query, e.g. in situations
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 480.
            Open

                public function num_rows()
                {
                    return @mysqli_num_rows($this->queryId);
                }
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 277.
            Open

                public function query($queryString, $line = '', $file = '')
                {
                    /* No empty queries, please, since PHP4 chokes on them. */
                    /* The empty query string is passed on from the constructor,
                    * when calling the class without a query, e.g. in situations
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 411.
            Open

                public function getLastInsertId($table, $field)
                {
                    if (!isset($table) || $table == '' || !isset($field) || $field == '') {
                        return -1;
                    }
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 455.
            Open

                public function unlock($haltOnError = true)
                {
                    $this->connect();
            
                    $res = @mysqli_query($this->linkId, 'unlock tables');
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 471.
            Open

                public function affectedRows()
                {
                    return @mysqli_affected_rows($this->linkId);
                }
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 256.
            Open

                public function query($queryString, $line = '', $file = '')
                {
                    /* No empty queries, please, since PHP4 chokes on them. */
                    /* The empty query string is passed on from the constructor,
                    * when calling the class without a query, e.g. in situations
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Remove error control operator '@' on line 301.
            Open

                public function fetchObject()
                {
                    $this->Record = @mysqli_fetch_object($this->queryId);
                    return $this->Record;
                }
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ErrorControlOperator

            Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

            Example

            function foo($filePath) {
                $file = @fopen($filPath); // hides exceptions
                $key = @$array[$notExistingKey]; // assigns null to $key
            }

            Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

            Avoid unused local variables such as '$haltPrev'.
            Open

                    $haltPrev = $this->haltOnError;
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            UnusedLocalVariable

            Since: 0.2

            Detects when a local variable is declared and/or assigned, but not used.

            Example

            class Foo {
                public function doSomething()
                {
                    $i = 5; // Unused
                }
            }

            Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

            Avoid classes with short names like Db. Configured minimum length is 3.
            Open

            class Db extends Generic implements Db_Interface
            {
                /**
                 * @var string
                 */
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            ShortClassName

            Since: 2.9

            Detects when classes or interfaces have a very short name.

            Example

            class Fo {
            
            }
            
            interface Fo {
            
            }

            Source https://phpmd.org/rules/naming.html#shortclassname

            The method next_record is not named in camelCase.
            Open

                public function next_record($resultType = MYSQLI_BOTH)
                {
                    if ($this->queryId === false) {
                        $this->haltmsg('next_record called with no query pending.');
                        return 0;
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            CamelCaseMethodName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name methods.

            Example

            class ClassName {
                public function get_name() {
                }
            }

            Source

            The method num_fields is not named in camelCase.
            Open

                public function num_fields()
                {
                    return @mysqli_num_fields($this->queryId);
                }
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            CamelCaseMethodName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name methods.

            Example

            class ClassName {
                public function get_name() {
                }
            }

            Source

            The method num_rows is not named in camelCase.
            Open

                public function num_rows()
                {
                    return @mysqli_num_rows($this->queryId);
                }
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            CamelCaseMethodName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name methods.

            Example

            class ClassName {
                public function get_name() {
                }
            }

            Source

            The method real_escape is not named in camelCase.
            Open

                public function real_escape($string = '')
                {
                    if ((!is_resource($this->linkId) || $this->linkId == 0) && !$this->connect()) {
                        return $this->escape($string);
                    }
            Severity: Minor
            Found in src/Mysqli/Db.php by phpmd

            CamelCaseMethodName

            Since: 0.2

            It is considered best practice to use the camelCase notation to name methods.

            Example

            class ClassName {
                public function get_name() {
                }
            }

            Source

            There are no issues that match your filters.

            Category
            Status