Completed
Push — master ( d685b1...8967da )
by Jared
02:15
created

SetStatement   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 12 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
c 4
b 0
f 0
lcom 1
cbo 1
dl 6
loc 50
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addValues() 0 6 1
A getSetValues() 0 4 1
A build() 6 20 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/**
4
 * @author Jared King <[email protected]>
5
 *
6
 * @link http://jaredtking.com
7
 *
8
 * @copyright 2015 Jared King
9
 * @license MIT
10
 */
11
namespace JAQB\Statement;
12
13
class SetStatement extends Statement
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $setValues = [];
19
20
    /**
21
     * Adds values to the statement.
22
     *
23
     * @return self
24
     */
25
    public function addValues(array $values)
26
    {
27
        $this->setValues = array_replace($this->setValues, $values);
28
29
        return $this;
30
    }
31
32
    /**
33
     * Gets the values being set.
34
     *
35
     * @return array
36
     */
37
    public function getSetValues()
38
    {
39
        return $this->setValues;
40
    }
41
42
    public function build()
43
    {
44
        // reset the parameterized values
45
        $this->values = [];
46
47
        $fields = [];
48 View Code Duplication
        foreach ($this->setValues as $key => $value) {
49
            if ($id = $this->escapeIdentifier($key)) {
50
                $fields[] = $id.' = ?';
51
                $this->values[] = $value;
52
            }
53
        }
54
55
        if (count($fields) == 0) {
56
            return '';
57
        }
58
59
        // generates SET `col1`=?,`col2`=?,`col3`=?
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
        return 'SET '.implode(', ', $fields);
61
    }
62
}
63