SetStatement   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addValues() 0 6 1
A getSetValues() 0 4 1
A build() 0 20 4
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
        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
        // produces "SET `col1`=?,`col2`=?,`col3`=?"
60
        return 'SET '.implode(', ', $fields);
61
    }
62
}
63