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

InsertBuilder::buildValuesForBulkInsert()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 2
crap 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