# yiisoft/yii2

framework/db/QueryBuilder.php

### Summary

F
4 days

#### The class QueryBuilder has 72 non-getter- and setter-methods. Consider refactoring QueryBuilder to keep number of methods under 25. Open

class QueryBuilder extends \yii\base\BaseObject
{
/**
* The prefix for automatically generated query binding parameters.
*/
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 0.1

A class with too many 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'. The default was changed from 10 to 25 in PHPMD 2.3.

Source: http://phpmd.org/rules/codesize.txt

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

class QueryBuilder extends \yii\base\BaseObject
{
/**
* The prefix for automatically generated query binding parameters.
*/
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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'.

Source: http://phpmd.org/rules/codesize.txt

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

class QueryBuilder extends \yii\base\BaseObject
{
/**
* The prefix for automatically generated query binding parameters.
*/
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 0.2.5

The Weighted Method Count (WMC) of a class is a good indicator of how much time and effort is required to modify and maintain this class. The WMC metric is defined as the sum of complexities of all methods declared in a class. A large number of methods also means that this class has a greater potential impact on derived classes.

Example:

class Foo {
public function bar() {
if ($a ==$b)  {
if ($a1 ==$b1) {
fiddle();
} elseif ($a2 ==$b2) {
fiddle();
} else {
}
}
}
public function baz() {
if ($a ==$b) {
if ($a1 ==$b1) {
fiddle();
} elseif ($a2 ==$b2) {
fiddle();
} else {
}
}
}
// Several other complex methods
}

#### Function buildSelect has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open

    public function buildSelect($columns, &$params, $distinct = false,$selectOption = null)
{
$select =$distinct ? 'SELECT DISTINCT' : 'SELECT';
if ($selectOption !== null) {$select .= ' ' . $selectOption; Found in framework/db/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 batchInsert has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open  public function batchInsert($table, $columns,$rows, &$params = []) { if (empty($rows)) {
return '';
}
Found in framework/db/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 build has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open

    public function build($query,$params = [])
{
$query =$query->prepare($this);$params = empty($params) ?$query->params : array_merge($params,$query->params);
Found in framework/db/QueryBuilder.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 quoteTableNames has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open

    private function quoteTableNames($tables, &$params)
{
foreach ($tables as$i => $table) { if ($table instanceof Query) {
list($sql,$params) = $this->build($table, $params); Found in framework/db/QueryBuilder.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 getExpressionBuilder has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open  public function getExpressionBuilder(ExpressionInterface$expression)
{
$className = get_class($expression);

if (!isset($this->expressionBuilders[$className])) {
Found in framework/db/QueryBuilder.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

#### The class QueryBuilder has 69 public methods and attributes. Consider reducing the number of public items to less than 45. Open

class QueryBuilder extends \yii\base\BaseObject
{
/**
* The prefix for automatically generated query binding parameters.
*/
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 0.1

A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.

Example:

public class Foo {
public $value; public$something;
public $var; // [... more more public attributes ...] public function doWork() {} public function doMoreWork() {} public function doWorkAgain() {} // [... more more public methods ...] } #### Function buildJoin has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open  public function buildJoin($joins, &$params) { if (empty($joins)) {
return '';
}
Found in framework/db/QueryBuilder.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 prepareInsertValues has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open

    protected function prepareInsertValues($table,$columns, $params = []) {$schema = $this->db->getSchema();$tableSchema = $schema->getTableSchema($table);
$columnSchemas =$tableSchema !== null ? $tableSchema->columns : []; Found in framework/db/QueryBuilder.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 buildColumns has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open  public function buildColumns($columns)
{
if (!is_array($columns)) { if (strpos($columns, '(') !== false) {
return $columns; Found in framework/db/QueryBuilder.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 addForeignKey has 7 arguments (exceeds 4 allowed). Consider refactoring. Open  public function addForeignKey($name, $table,$columns, $refTable,$refColumns, $delete = null,$update = null)
Found in framework/db/QueryBuilder.php - About 50 mins to fix

#### Function getColumnType has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open

    public function getColumnType($type) { if ($type instanceof ColumnSchemaBuilder) {
$type =$type->__toString();
}
Found in framework/db/QueryBuilder.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

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

    protected function prepareInsertSelectSubQuery($columns,$schema, $params = []) { if (!is_array($columns->select) || empty($columns->select) || in_array('*',$columns->select)) {
throw new InvalidArgumentException('Expected select query object with enumerated (named) parameters');
}
Found in framework/db/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 buildWithQueries has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open

    public function buildWithQueries($withs, &$params)
{
if (empty($withs)) { return ''; } Found in framework/db/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 class QueryBuilder has 1756 lines of code. Current threshold is 1000. Avoid really long classes. Open class QueryBuilder extends \yii\base\BaseObject { /** * The prefix for automatically generated query binding parameters. */ Found in framework/db/QueryBuilder.php by phpmd #### 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 '';
}
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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
}
}

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

    public function build($query,$params = [])
{
$query =$query->prepare($this);$params = empty($params) ?$query->params : array_merge($params,$query->params);
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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; } } } } #### 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 '';
}
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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; } } } } #### The method buildSelect() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open  public function buildSelect($columns, &$params,$distinct = false, $selectOption = null) {$select = $distinct ? 'SELECT DISTINCT' : 'SELECT'; if ($selectOption !== null) {
$select .= ' ' .$selectOption;
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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; } } } } #### The class QueryBuilder has a coupling between objects value of 15. Consider to reduce the number of dependencies under 13. Open class QueryBuilder extends \yii\base\BaseObject { /** * The prefix for automatically generated query binding parameters. */ Found in framework/db/QueryBuilder.php by phpmd Since: PHPMD 1.1.0 A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability Example: class Foo { /** * @var \foo\bar\X */ private$x = null;

/**
* @var \foo\bar\Y
*/
private $y = null; /** * @var \foo\bar\Z */ private$z = null;

public function setFoo(\Foo $foo) {} public function setBar(\Bar$bar) {}
public function setBaz(\Baz $baz) {} /** * @return \SplObjectStorage * @throws \OutOfRangeException * @throws \InvalidArgumentException * @throws \ErrorException */ public function process(\Iterator$it) {}

// ...
}

#### The method checkIntegrity has a boolean flag argument $check, which is a certain sign of a Single Responsibility Principle violation. Open  public function checkIntegrity($check = true, $schema = '',$table = '')
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example:

class Foo {
public function bar($flag = true) { } } #### The method createIndex has a boolean flag argument$unique, which is a certain sign of a Single Responsibility Principle violation. Open

    public function createIndex($name,$table, $columns,$unique = false)
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example:

class Foo {
public function bar($flag = true) { } } #### The method buildSelect has a boolean flag argument$distinct, which is a certain sign of a Single Responsibility Principle violation. Open

    public function buildSelect($columns, &$params, $distinct = false,$selectOption = null)
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example:

class Foo {
public function bar($flag = true) { } } #### Avoid unused parameters such as '$schema'. Open

    public function checkIntegrity($check = true,$schema = '', $table = '') Found in framework/db/QueryBuilder.php by phpmd Since: PHPMD 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 } } #### Avoid unused parameters such as '$table'. Open

    public function upsert($table,$insertColumns, $updateColumns, &$params)
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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
}
}

#### Avoid unused parameters such as '$table'. Open  public function checkIntegrity($check = true, $schema = '',$table = '')
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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
}
}

#### Avoid unused parameters such as '$check'. Open  public function checkIntegrity($check = true, $schema = '',$table = '')
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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
}
}

{
// $howdy is not used } } #### Avoid unused parameters such as '$table'. Open

    public function addDefaultValue($name,$table, $column,$value)
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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
}
}

{
// $howdy is not used } } #### Avoid unused parameters such as '$value'. Open

    public function addDefaultValue($name,$table, $column,$value)
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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
}
}

{
// $howdy is not used } } #### Avoid unused parameters such as '$name'. Open

    public function addDefaultValue($name,$table, $column,$value)
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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
}
}

{
// $howdy is not used } } #### Avoid unused local variables such as '$i'. Open

        foreach ($withs as$i => $with) { Found in framework/db/QueryBuilder.php by phpmd Since: PHPMD 0.2 Detects when a local variable is declared and/or assigned, but not used. Example: class Foo { public function doSomething() {$i = 5; // Unused
}
}

{
// $howdy is not used } } #### Avoid unused parameters such as '$table'. Open

    public function dropDefaultValue($name,$table)
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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
}
}

{
// $howdy is not used } } #### Avoid unused parameters such as '$table'. Open

    public function resetSequence($table,$value = null)
Found in framework/db/QueryBuilder.php by phpmd

Since: PHPMD 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
}
}

#### 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);
Found in framework/db/QueryBuilder.php and 1 other location - About 7 hrs to fix
framework/db/oci/QueryBuilder.php on lines 314..335

## 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 192.

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.

## Further Reading

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

    public function addPrimaryKey($name,$table, $columns) { if (is_string($columns)) {
$columns = preg_split('/\s*,\s*/',$columns, -1, PREG_SPLIT_NO_EMPTY);
}
Found in framework/db/QueryBuilder.php and 1 other location - About 3 hrs to fix
framework/db/QueryBuilder.php on lines 940..952

## 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 122.

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.

## Further Reading

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

    public function addUnique($name,$table, $columns) { if (is_string($columns)) {
$columns = preg_split('/\s*,\s*/',$columns, -1, PREG_SPLIT_NO_EMPTY);
}
Found in framework/db/QueryBuilder.php and 1 other location - About 3 hrs to fix
framework/db/QueryBuilder.php on lines 759..772

## 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 122.

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.

## Further Reading

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

        $clauses = [$this->buildSelect($query->select,$params, $query->distinct,$query->selectOption),
$this->buildFrom($query->from, $params),$this->buildJoin($query->join,$params),
$this->buildWhere($query->where, $params), Found in framework/db/QueryBuilder.php and 1 other location - About 1 hr to fix framework/db/sqlite/QueryBuilder.php on lines 491..498 ## 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 97. 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 $sql = 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' ADD CONSTRAINT ' . $this->db->quoteColumnName($name)
. ' FOREIGN KEY (' . $this->buildColumns($columns) . ')'
. ' REFERENCES ' . $this->db->quoteTableName($refTable)
. ' (' . $this->buildColumns($refColumns) . ')';
Found in framework/db/QueryBuilder.php and 1 other location - About 1 hr to fix
framework/db/oci/QueryBuilder.php on lines 176..180

## 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 85.

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.

## Further Reading

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

        return 'INSERT INTO ' . $this->db->quoteTableName($table)
. (!empty($names) ? ' (' . implode(', ',$names) . ')' : '')
. (!empty($placeholders) ? ' VALUES (' . implode(', ',$placeholders) . ')' : \$values);
Found in framework/db/QueryBuilder.php and 1 other location - About 40 mins to fix
framework/db/sqlite/QueryBuilder.php on lines 83..85

## 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 78.

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.