yiisoft/yii2

View on GitHub
framework/db/oci/QueryBuilder.php

Summary

Maintainability
D
2 days
Test Coverage

The class QueryBuilder has an overall complexity of 53 which is very high. The configured complexity threshold is 50.
Open

class QueryBuilder extends \yii\db\QueryBuilder
{
    /**
     * @var array mapping from abstract column types (keys) to physical column types (values).
     */
Severity: Minor
Found in framework/db/oci/QueryBuilder.php by phpmd

The class QueryBuilder has 11 public methods. Consider refactoring QueryBuilder to keep number of public methods under 10.
Open

class QueryBuilder extends \yii\db\QueryBuilder
{
    /**
     * @var array mapping from abstract column types (keys) to physical column types (values).
     */
Severity: Minor
Found in framework/db/oci/QueryBuilder.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

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

Function batchInsert has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    public function batchInsert($table, $columns, $rows, &$params = [])
    {
        if (empty($rows)) {
            return '';
        }
Severity: Minor
Found in framework/db/oci/QueryBuilder.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

Function upsert has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    public function upsert($table, $insertColumns, $updateColumns, &$params)
    {
        /** @var Constraint[] $constraints */
        list($uniqueNames, $insertNames, $updateNames) = $this->prepareUpsertColumns($table, $insertColumns, $updateColumns, $constraints);
        if (empty($uniqueNames)) {
Severity: Minor
Found in framework/db/oci/QueryBuilder.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 addForeignKey has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
Severity: Major
Found in framework/db/oci/QueryBuilder.php - About 50 mins to fix

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

        protected function prepareInsertValues($table, $columns, $params = [])
        {
            list($names, $placeholders, $values, $params) = parent::prepareInsertValues($table, $columns, $params);
            if (!$columns instanceof Query && empty($names)) {
                $tableSchema = $this->db->getSchema()->getTableSchema($table);
    Severity: Minor
    Found in framework/db/oci/QueryBuilder.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 executeResetSequence has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        public function executeResetSequence($table, $value = null)
        {
            $tableSchema = $this->db->getTableSchema($table);
            if ($tableSchema === null) {
                throw new InvalidArgumentException("Unknown table: $table");
    Severity: Minor
    Found in framework/db/oci/QueryBuilder.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 batchInsert() has an NPath complexity of 224. The configured NPath complexity threshold is 200.
    Open

        public function batchInsert($table, $columns, $rows, &$params = [])
        {
            if (empty($rows)) {
                return '';
            }
    Severity: Minor
    Found in framework/db/oci/QueryBuilder.php by phpmd

    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 upsert() has an NPath complexity of 1728. The configured NPath complexity threshold is 200.
    Open

        public function upsert($table, $insertColumns, $updateColumns, &$params)
        {
            /** @var Constraint[] $constraints */
            list($uniqueNames, $insertNames, $updateNames) = $this->prepareUpsertColumns($table, $insertColumns, $updateColumns, $constraints);
            if (empty($uniqueNames)) {
    Severity: Minor
    Found in framework/db/oci/QueryBuilder.php by phpmd

    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 batchInsert() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
    Open

        public function batchInsert($table, $columns, $rows, &$params = [])
        {
            if (empty($rows)) {
                return '';
            }
    Severity: Minor
    Found in framework/db/oci/QueryBuilder.php by phpmd

    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

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

        public function upsert($table, $insertColumns, $updateColumns, &$params)
        {
            /** @var Constraint[] $constraints */
            list($uniqueNames, $insertNames, $updateNames) = $this->prepareUpsertColumns($table, $insertColumns, $updateColumns, $constraints);
            if (empty($uniqueNames)) {
    Severity: Minor
    Found in framework/db/oci/QueryBuilder.php by phpmd

    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

    Avoid unused parameters such as '$table'.
    Open

        public function dropIndex($name, $table)
    Severity: Minor
    Found in framework/db/oci/QueryBuilder.php by phpmd

    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 assigning values to variables in if clauses and the like (line '307', column '14').
    Open

        public function batchInsert($table, $columns, $rows, &$params = [])
        {
            if (empty($rows)) {
                return '';
            }
    Severity: Minor
    Found in framework/db/oci/QueryBuilder.php by phpmd

    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

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

            foreach ($rows as $row) {
                $vs = [];
                foreach ($row as $i => $value) {
                    if (isset($columns[$i], $columnSchemas[$columns[$i]])) {
                        $value = $columnSchemas[$columns[$i]]->dbTypecast($value);
    Severity: Major
    Found in framework/db/oci/QueryBuilder.php and 1 other location - About 6 hrs to fix
    framework/db/QueryBuilder.php on lines 465..486

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

    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

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

        protected function prepareInsertValues($table, $columns, $params = [])
        {
            list($names, $placeholders, $values, $params) = parent::prepareInsertValues($table, $columns, $params);
            if (!$columns instanceof Query && empty($names)) {
                $tableSchema = $this->db->getSchema()->getTableSchema($table);
    Severity: Major
    Found in framework/db/oci/QueryBuilder.php and 1 other location - About 5 hrs to fix
    framework/db/mysql/QueryBuilder.php on lines 256..270

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

    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

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

        public $typeMap = [
            Schema::TYPE_PK => 'NUMBER(10) NOT NULL PRIMARY KEY',
            Schema::TYPE_UPK => 'NUMBER(10) UNSIGNED NOT NULL PRIMARY KEY',
            Schema::TYPE_BIGPK => 'NUMBER(20) NOT NULL PRIMARY KEY',
            Schema::TYPE_UBIGPK => 'NUMBER(20) UNSIGNED NOT NULL PRIMARY KEY',
    Severity: Major
    Found in framework/db/oci/QueryBuilder.php and 3 other locations - About 4 hrs to fix
    framework/db/cubrid/QueryBuilder.php on lines 27..49
    framework/db/mssql/QueryBuilder.php on lines 27..49
    framework/db/sqlite/QueryBuilder.php on lines 30..52

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

    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

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

            if ($updateColumns === true) {
                $updateColumns = [];
                foreach ($updateNames as $name) {
                    $quotedName = $this->db->quoteColumnName($name);
                    if (strrpos($quotedName, '.') === false) {
    Severity: Major
    Found in framework/db/oci/QueryBuilder.php and 3 other locations - About 35 mins to fix
    framework/db/cubrid/QueryBuilder.php on lines 107..116
    framework/db/mssql/QueryBuilder.php on lines 577..586
    framework/db/pgsql/QueryBuilder.php on lines 425..434

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

    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