Completed
Push — 3.x-builder-quoter ( 067851 )
by Paul
02:03
created

InsertBuilder   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 68
ccs 28
cts 30
cp 0.9333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildInto() 0 5 1
A buildValuesForInsert() 0 19 3
A buildValuesForBulkInsert() 0 17 3
1
<?php
2
namespace Aura\SqlQuery\Common;
3
4
use Aura\SqlQuery\AbstractBuilder;
5
6
class InsertBuilder extends AbstractBuilder
7
{
8
9
    /**
10
     *
11
     * Builds the INTO clause.
12
     *
13
     * @return string
14
     *
15
     */
16 42
    public function buildInto($into)
17
    {
18 42
        $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...
19 42
        return " INTO {$into}";
20
    }
21
22
    /**
23
     *
24
     * Builds the inserted columns and values of the statement.
25
     *
26
     * @return string
27
     *
28
     */
29 22
    public function buildValuesForInsert($col_values)
30
    {
31 22
        $cols = [];
32 22
        $values = [];
33 22
        foreach ($col_values as $col => $value) {
34 22
            $cols[] = $this->quoter->quoteName($col);
35 22
            if ($value instanceof RawValue) {
0 ignored issues
show
Bug introduced by
The class Aura\SqlQuery\Common\RawValue does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
36
                $values[] = $this->quoter->quoteNamesIn((string) $value);
37
            } else {
38 22
                $values[] = (string) $value;
39
            }
40 22
        }
41
42
        return ' ('
43 22
            . $this->indentCsv($cols)
44 22
            . PHP_EOL . ') VALUES ('
45 22
            . $this->indentCsv($values)
46 22
            . PHP_EOL . ')';
47
    }
48
49
    /**
50
     *
51
     * Builds the bulk-inserted columns and values of the statement.
52
     *
53
     * @return string
54
     *
55
     */
56 20
    public function buildValuesForBulkInsert($col_order, $col_values_bulk)
57
    {
58 20
        $cols = [];
59 20
        foreach ($col_order as $col) {
60 20
            $cols[] = $this->quoter->quoteName($col);
61 20
        }
62 20
        $cols = "    (" . implode(', ', $cols) . ")";
63
64 20
        $vals = array();
65 20
        foreach ($col_values_bulk as $row_values) {
66 20
            $vals[] = "    (" . implode(', ', $row_values) . ")";
67 20
        }
68
69 20
        return PHP_EOL . $cols . PHP_EOL
70 20
            . "VALUES" . PHP_EOL
71 20
            . implode("," . PHP_EOL, $vals);
72
    }
73
}
74