qcubed/framework

View on GitHub
includes/database/QMySqlDatabase.class.php

Summary

Maintainability
D
2 days
Test Coverage

Function __construct has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
Open

        public function __construct($mixFieldData, $objDb = null) {
            $this->strName = $mixFieldData->name;
            $this->strOriginalName = $this->strName;
            $this->strTable = $mixFieldData->table;
            $this->strOriginalTable = $mixFieldData->table;
Severity: Minor
Found in includes/database/QMySqlDatabase.class.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

Method __construct has 83 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        public function __construct($mixFieldData, $objDb = null) {
            $this->strName = $mixFieldData->name;
            $this->strOriginalName = $this->strName;
            $this->strTable = $mixFieldData->table;
            $this->strOriginalTable = $mixFieldData->table;
Severity: Major
Found in includes/database/QMySqlDatabase.class.php - About 3 hrs to fix

    Avoid deeply nested control flow statements.
    Open

                            if ($intCommaPosition !== false) {
                                $this->intMaxLength = substr($this->intMaxLength, 0, $intCommaPosition);
                                $this->intMaxLength++; // make room for decimal point
                            }
    Severity: Major
    Found in includes/database/QMySqlDatabase.class.php - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if (!is_numeric($this->intMaxLength))
                                throw new Exception("Not a valid Column Length: " . $objRow["Type"]);            
      Severity: Major
      Found in includes/database/QMySqlDatabase.class.php - About 45 mins to fix

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

                public function Connect() {
                    // Lookup Adapter-Specific Connection Properties
                    $strServer = $this->Server;
                    $strName = $this->Database;
                    $strUsername = $this->Username;
        Severity: Minor
        Found in includes/database/QMySqlDatabase.class.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

        The method __construct() has an NPath complexity of 252. The configured NPath complexity threshold is 200.
        Open

                public function __construct($mixFieldData, $objDb = null) {
                    $this->strName = $mixFieldData->name;
                    $this->strOriginalName = $this->strName;
                    $this->strTable = $mixFieldData->table;
                    $this->strOriginalTable = $mixFieldData->table;

        NPathComplexity

        Since: 0.1

        The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

        Example

        class Foo {
            function bar() {
                // lots of complicated code
            }
        }

        Source https://phpmd.org/rules/codesize.html#npathcomplexity

        The method __construct() has 100 lines of code. Current threshold is set to 100. Avoid really long methods.
        Open

                public function __construct($mixFieldData, $objDb = null) {
                    $this->strName = $mixFieldData->name;
                    $this->strOriginalName = $this->strName;
                    $this->strTable = $mixFieldData->table;
                    $this->strOriginalTable = $mixFieldData->table;

        The method __construct() has a Cyclomatic Complexity of 24. The configured cyclomatic complexity threshold is 10.
        Open

                public function __construct($mixFieldData, $objDb = null) {
                    $this->strName = $mixFieldData->name;
                    $this->strOriginalName = $this->strName;
                    $this->strTable = $mixFieldData->table;
                    $this->strOriginalTable = $mixFieldData->table;

        CyclomaticComplexity

        Since: 0.1

        Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

        Example

        // Cyclomatic Complexity = 11
        class Foo {
        1   public function example() {
        2       if ($a == $b) {
        3           if ($a1 == $b1) {
                        fiddle();
        4           } elseif ($a2 == $b2) {
                        fiddle();
                    } else {
                        fiddle();
                    }
        5       } elseif ($c == $d) {
        6           while ($c == $d) {
                        fiddle();
                    }
        7        } elseif ($e == $f) {
        8           for ($n = 0; $n < $h; $n++) {
                        fiddle();
                    }
                } else {
                    switch ($z) {
        9               case 1:
                            fiddle();
                            break;
        10              case 2:
                            fiddle();
                            break;
        11              case 3:
                            fiddle();
                            break;
                        default:
                            fiddle();
                            break;
                    }
                }
            }
        }

        Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

        Missing class import via use statement (line '97', column '21').
        Open

                    $objResult = new QMySqlDatabaseResult(mysql_list_fields($this->Database, $strTableName, $this->objDb), $this);

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '121', column '39').
        Open

                        array_push($objArrayToReturn, new QMySqlDatabaseField($objField, $this->objDb));

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '253', column '16').
        Open

                            throw new Exception("Unable to determine MySqli Database Field Type: " . $mixFieldData->type);

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '79', column '15').
        Open

                        throw new QMySqliDatabaseException(mysql_error($this->objDb), mysql_errno($this->objDb), $strNonQuery);

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '29', column '15').
        Open

                        throw new QMySqliDatabaseException("Unable to connect to Database Server: $strServer", -1, null);

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '31', column '15').
        Open

                        throw new QMySqliDatabaseException(mysql_error($this->objDb), mysql_errno($this->objDb), null);

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '68', column '15').
        Open

                        throw new QMySqliDatabaseException(mysql_error($this->objDb), mysql_errno($this->objDb), $strQuery);

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '194', column '31').
        Open

                                  throw new Exception("Not a valid Column Length: " . $objRow["Type"]);            

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '35', column '15').
        Open

                        throw new QMySqliDatabaseException("Unable to select the Database: $strName", -1, null);

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '128', column '16').
        Open

                        return new QMySqlDatabaseField($objField, $this->objDb);

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '37', column '15').
        Open

                        throw new QMySqliDatabaseException(mysql_error($this->objDb), mysql_errno($this->objDb), null);

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Missing class import via use statement (line '71', column '34').
        Open

                    $objMySqlDatabaseResult = new QMySqlDatabaseResult($objResult, $this);

        MissingImport

        Since: 2.7.0

        Importing all external classes in a file through use statements makes them clearly visible.

        Example

        function make() {
            return new \stdClass();
        }

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

        Avoid using static access to class 'QType' in method '__construct'.
        Open

                    $this->blnNotNull = QType::Cast($mixFieldData->not_null, QType::Boolean);

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

        Source https://phpmd.org/rules/cleancode.html#staticaccess

        Avoid using static access to class 'QType' in method '__construct'.
        Open

                    $this->blnUnique = QType::Cast($mixFieldData->unique_key, QType::Boolean);

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

        Source https://phpmd.org/rules/cleancode.html#staticaccess

        Avoid assigning values to variables in if clauses and the like (line '127', column '8').
        Open

                public function FetchField() {
                    if ($objField = mysql_fetch_field($this->objMySqlResult))
                        return new QMySqlDatabaseField($objField, $this->objDb);
                }

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

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

        Avoid using static access to class 'QType' in method '__construct'.
        Open

                    $this->blnPrimaryKey = QType::Cast($mixFieldData->primary_key, QType::Boolean);

        StaticAccess

        Since: 1.4.0

        Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

        Example

        class Foo
        {
            public function bar()
            {
                Bar::baz();
            }
        }

        Source https://phpmd.org/rules/cleancode.html#staticaccess

        Avoid unused parameters such as '$strColumnName'.
        Open

                public function InsertId($strTableName = null, $strColumnName = null) {

        UnusedFormalParameter

        Since: 0.2

        Avoid passing parameters to methods or constructors and then not using those parameters.

        Example

        class Foo
        {
            private function bar($howdy)
            {
                // $howdy is not used
            }
        }

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

        Avoid unused parameters such as '$strTableName'.
        Open

                public function InsertId($strTableName = null, $strColumnName = null) {

        UnusedFormalParameter

        Since: 0.2

        Avoid passing parameters to methods or constructors and then not using those parameters.

        Example

        class Foo
        {
            private function bar($howdy)
            {
                // $howdy is not used
            }
        }

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

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

                              if ((count($strLengthArray) > 1) &&
                                (strtolower($strLengthArray[0]) != 'enum') &&
                                (strtolower($strLengthArray[0]) != 'set')) {
                                $strLengthArray = explode(")", $strLengthArray[1]);
                                $this->intMaxLength = $strLengthArray[0];
        Severity: Major
        Found in includes/database/QMySqlDatabase.class.php and 1 other location - About 5 hrs to fix
        includes/database/QMySqliDatabase.class.php on lines 658..674

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

        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

        Avoid excessively long variable names like $objMySqlDatabaseResult. Keep variable name length under 20.
        Open

                    $objMySqlDatabaseResult = new QMySqlDatabaseResult($objResult, $this);

        LongVariable

        Since: 0.2

        Detects when a field, formal or local variable is declared with a long name.

        Example

        class Something {
            protected $reallyLongIntName = -3; // VIOLATION - Field
            public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
                $otherReallyLongName = -5; // VIOLATION - Local
                for ($interestingIntIndex = 0; // VIOLATION - For
                     $interestingIntIndex < 10;
                     $interestingIntIndex++ ) {
                }
            }
        }

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

        Constant Adapter should be defined in uppercase
        Open

                const Adapter = 'MySql Legacy Database Adapter for MySQL 4';

        ConstantNamingConventions

        Since: 0.2

        Class/Interface constant names should always be defined in uppercase.

        Example

        class Foo {
            const MY_NUM = 0; // ok
            const myTest = ""; // fail
        }

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

        The method CountRows is not named in camelCase.
        Open

                public function CountRows() {
                    return mysql_num_rows($this->objMySqlResult);
                }

        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 CountFields is not named in camelCase.
        Open

                public function CountFields() {
                    return mysql_num_fields($this->objMySqlResult);
                }

        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 FetchFields is not named in camelCase.
        Open

                public function FetchFields() {
                    $objArrayToReturn = array();
                    while ($objField = mysql_fetch_field($this->objMySqlResult)) {
                        array_push($objArrayToReturn, new QMySqlDatabaseField($objField, $this->objDb));
                    }

        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 Close is not named in camelCase.
        Open

                public function Close() {
                    mysql_free_result($this->objMySqlResult);
                }

        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 FetchField is not named in camelCase.
        Open

                public function FetchField() {
                    if ($objField = mysql_fetch_field($this->objMySqlResult))
                        return new QMySqlDatabaseField($objField, $this->objDb);
                }

        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 InsertId is not named in camelCase.
        Open

                public function InsertId($strTableName = null, $strColumnName = null) {
                    $result = $this->Query('SELECT LAST_INSERT_ID();');
                    $data = $result->FetchArray();
                    $result->Close();
                    return $data[0];

        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 FetchArray is not named in camelCase.
        Open

                public function FetchArray() {
                    return mysql_fetch_array($this->objMySqlResult);
                }

        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 FetchRow is not named in camelCase.
        Open

                public function FetchRow() {
                    return mysql_fetch_row($this->objMySqlResult);
                }

        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 GetFieldsForTable is not named in camelCase.
        Open

                public function GetFieldsForTable($strTableName) {
                    $objResult = new QMySqlDatabaseResult(mysql_list_fields($this->Database, $strTableName, $this->objDb), $this);
                    return $objResult->FetchFields();
                }

        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 ExecuteNonQuery is not named in camelCase.
        Open

                protected function ExecuteNonQuery($strNonQuery) {
                    // Perform the Query
                    mysql_query($strNonQuery, $this->objDb);
                    if (mysql_errno($this->objDb))
                        throw new QMySqliDatabaseException(mysql_error($this->objDb), mysql_errno($this->objDb), $strNonQuery);

        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 ExecuteQuery is not named in camelCase.
        Open

                protected function ExecuteQuery($strQuery) {
                    // Perform the Query
                    $objResult = mysql_query($strQuery, $this->objDb);            
                    if (mysql_errno($this->objDb))
                        throw new QMySqliDatabaseException(mysql_error($this->objDb), mysql_errno($this->objDb), $strQuery);

        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 MySqlFetchField is not named in camelCase.
        Open

                public function MySqlFetchField() {
                    return mysql_fetch_field($this->objMySqlResult);
                }

        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 Connect is not named in camelCase.
        Open

                public function Connect() {
                    // Lookup Adapter-Specific Connection Properties
                    $strServer = $this->Server;
                    $strName = $this->Database;
                    $strUsername = $this->Username;

        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 Close is not named in camelCase.
        Open

                public function Close() {
                    mysql_close($this->objDb);
        
                    // Update Connected Flag
                    $this->blnConnectedFlag = false;

        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