Completed
Push — 3.x ( e5eb1c...76cecd )
by Paul
9s
created

InsertBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 51
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildInto() 0 4 1
A buildValuesForInsert() 0 8 1
A buildValuesForBulkInsert() 0 11 2
1
<?php
2
namespace Aura\SqlQuery\Common;
3
4
class InsertBuilder extends AbstractBuilder
5
{
6
7
    /**
8
     *
9
     * Builds the INTO clause.
10
     *
11
     * @return string
12
     *
13
     */
14 42
    public function buildInto($into)
15
    {
16 42
        return " INTO {$into}";
17
    }
18
19
20
    /**
21
     *
22
     * Builds the inserted columns and values of the statement.
23
     *
24
     * @return string
25
     *
26
     */
27 22
    public function buildValuesForInsert($col_values)
28
    {
29
        return ' ('
30 22
            . $this->indentCsv(array_keys($col_values))
31 22
            . PHP_EOL . ') VALUES ('
32 22
            . $this->indentCsv(array_values($col_values))
33 22
            . PHP_EOL . ')';
34
    }
35
36
    /**
37
     *
38
     * Builds the bulk-inserted columns and values of the statement.
39
     *
40
     * @return string
41
     *
42
     */
43 20
    public function buildValuesForBulkInsert($col_order, $col_values_bulk)
44
    {
45 20
        $cols = "    (" . implode(', ', $col_order) . ")";
46 20
        $vals = array();
47 20
        foreach ($col_values_bulk as $row_values) {
48 20
            $vals[] = "    (" . implode(', ', $row_values) . ")";
49
        }
50 20
        return PHP_EOL . $cols . PHP_EOL
51 20
            . "VALUES" . PHP_EOL
52 20
            . implode("," . PHP_EOL, $vals);
53
    }
54
}
55