Insert::values()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Rougin\Windstorm\Doctrine;
4
5
use Doctrine\DBAL\Query\QueryBuilder;
6
use Rougin\Windstorm\Doctrine\Builder;
7
use Rougin\Windstorm\InsertInterface;
8
9
/**
10
 * Insert Query
11
 *
12
 * @package Windstorm
13
 * @author  Rougin Gutib <[email protected]>
14
 */
15
class Insert implements InsertInterface
16
{
17
    /**
18
     * @var \Doctrine\DBAL\Query\QueryBuilder
19
     */
20
    protected $builder;
21
22
    /**
23
     * @var \Rougin\Windstorm\Doctrine\Query
24
     */
25
    protected $query;
26
27
    /**
28
     * @var string
29
     */
30
    protected $table = '';
31
32
    /**
33
     * Initializes the query instance.
34
     *
35
     * @param \Rougin\Windstorm\Doctrine\Query  $query
36
     * @param \Doctrine\DBAL\Query\QueryBuilder $builder
37
     * @param string                            $table
38
     */
39 9
    public function __construct(Query $query, QueryBuilder $builder, $table)
40
    {
41 9
        $this->builder = $builder;
42
43 9
        $this->query = $query;
44
45 9
        $this->table = $table;
46 9
    }
47
48
    /**
49
     * Sets the values to be inserted.
50
     *
51
     * @param  array  $data
52
     * @return \Rougin\Windstorm\QueryInterface
53
     */
54 9
    public function values(array $data)
55
    {
56 9
        $this->builder->insert($this->table);
57
58 9
        $index = 0;
59
60 9
        foreach ($data as $key => $value)
61
        {
62 9
            $this->builder->setParameter($index, $value);
63
64 9
            $data[$key] = '?';
65
66 9
            $index = $index + 1;
67 6
        }
68
69 9
        $this->builder->add('values', /** @scrutinizer ignore-type */ $data);
70
71 9
        return $this->query->builder($this->builder);
72
    }
73
}
74