Passed
Push — master ( 7c9482...a7cffb )
by Rougin
01:44
created

Update::where()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Rougin\Windstorm\Doctrine;
4
5
use Rougin\Windstorm\Doctrine\Builder;
6
use Rougin\Windstorm\UpdateInterface;
7
8
/**
9
 * Update Query
10
 *
11
 * @package Windstorm
12
 * @author  Rougin Gutib <[email protected]>
13
 */
14
class Update implements UpdateInterface
15
{
16
    /**
17
     * @var \Rougin\Windstorm\Doctrine\Builder
18
     */
19
    protected $builder;
20
21
    /**
22
     * @var \Rougin\Windstorm\Doctrine\Query
23
     */
24
    protected $query;
25
26
    /**
27
     * Initializes the query instance.
28
     *
29
     * @param \Rougin\Windstorm\Doctrine\Query   $query
30
     * @param \Rougin\Windstorm\Doctrine\Builder $builder
31
     * @param string                             $table
32
     * @param string                             $initial
33
     */
34 3
    public function __construct(Query $query, Builder $builder, $table, $initial)
35
    {
36 3
        $this->builder = $builder->update($table, $initial);
37
38 3
        $this->query = $query;
39 3
    }
40
41
    /**
42
     * Sets a new value for a column.
43
     *
44
     * @param  string $key
45
     * @param  mixed  $value
46
     * @return self
47
     */
48 3
    public function set($key, $value)
49
    {
50 3
        $placeholder = $key[0] === ':' ? $key : ':' . $key;
51
52 3
        $this->builder->setParameter($placeholder, $value);
53
54 3
        $key = (string) $key . ' = ' . $placeholder;
55
56 3
        $this->builder->add('set', (string) $key, true);
57
58 3
        return $this;
59
    }
60
61
    /**
62
     * Generates a WHERE query.
63
     *
64
     * @param  string $key
65
     * @return \Rougin\Windstorm\WhereInterface
66
     */
67 3
    public function where($key)
68
    {
69 3
        $this->query->builder($this->builder);
70
71 3
        return $this->query->where($key);
72
    }
73
}
74