Completed
Push — 3.x-builder ( 47ec34 )
by Paul
02:38
created

InsertBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 51
ccs 16
cts 16
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 " . $this->quoter->quoteName($into);
0 ignored issues
show
Bug introduced by
The property quoter does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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 20
        }
50 20
        return PHP_EOL . $cols . PHP_EOL
51 20
            . "VALUES" . PHP_EOL
52 20
            . implode("," . PHP_EOL, $vals);
53
    }
54
}
55