Insert   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 54
wmc 7
lcom 1
cbo 3
ccs 23
cts 23
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A toString() 0 9 1
A insert() 0 6 1
A values() 0 6 1
A buildInsertString() 0 4 1
A buildValuesString() 0 6 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