Insert::values()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Muffin\Queries;
4
5
use Muffin\Query;
6
use Muffin\Traits\EscaperAware;
7
8
class Insert implements Query
9
{
10
    use EscaperAware;
11
12
    private
13
        $insertPart,
14
        $valuesPart;
15
16 3
    public function __construct($table = null)
17
    {
18 3
        $this->valuesPart = new Snippets\Values();
19
20 3
        if(! empty($table))
21 3
        {
22 2
            $this->insertPart = new Snippets\TableName($table);
23 2
        }
24 3
    }
25
26 3
    public function toString()
27
    {
28
        $queryParts = array(
29 3
            $this->buildInsertString(),
30 3
            $this->buildValuesString(),
31 3
        );
32
33 3
        return implode(' ', $queryParts);
34
    }
35
36 1
    public function insert($table)
0 ignored issues
show
Best Practice introduced by
Using PHP4-style constructors that are named like the class is not recommend; better use the more explicit __construct method.
Loading history...
37
    {
38 1
        $this->insertPart = new Snippets\TableName($table);
39
40 1
        return $this;
41
    }
42
43 3
    public function values(array $values)
44
    {
45 3
        $this->valuesPart->values($values);
46
47 3
        return $this;
48
    }
49
50 3
    private function buildInsertString()
51
    {
52 3
        return sprintf('INSERT INTO %s', $this->insertPart->toString());
53
    }
54
55 3
    private function buildValuesString()
56
    {
57 3
        $this->valuesPart->setEscaper($this->escaper);
58
59 3
        return $this->valuesPart->toString();
60
    }
61
}
62