detain/db_abstraction

View on GitHub
src/Pdo/Db.php

Summary

Maintainability
A
3 hrs
Test Coverage

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

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

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

        public function connect($database = '', $host = '', $user = '', $password = '', $driver = 'mysql')
        {
            /* Handle defaults */
            if ('' == $database) {
                $database = $this->database;
    Severity: Minor
    Found in src/Pdo/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

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

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

      Function query has a Cognitive Complexity of 7 (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/Pdo/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

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

          public function affectedRows()
          {
              return @$this->queryId->rowCount();
          }
      Severity: Minor
      Found in src/Pdo/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 classes with short names like Db. Configured minimum length is 3.
      Open

      class Db extends Generic implements Db_Interface
      {
          /* public: connection parameters */
          public $driver = 'mysql';
          public $Rows = [];
      Severity: Minor
      Found in src/Pdo/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 num_rows is not named in camelCase.
      Open

          public function num_rows()
          {
              return count($this->Rows);
          }
      Severity: Minor
      Found in src/Pdo/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()
          {
              $keys = array_keys($this->Rows);
              return count($this->Rows[$keys[0]]);
          }
      Severity: Minor
      Found in src/Pdo/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 next_record is not named in camelCase.
      Open

          public function next_record($resultType = MYSQLI_ASSOC)
          {
              // PDO result types so far seem to be +1
              ++$resultType;
              if (!$this->queryId) {
      Severity: Minor
      Found in src/Pdo/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