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

SetStatement::getSetValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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