Set::set()   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\Snippets;
4
5
use Muffin\Snippet;
6
use Muffin\Type;
7
use Muffin\Types;
8
use Muffin\Conditions;
9
use Muffin\Traits\EscaperAware;
10
use Muffin\Traits\TypeGuesser;
11
12
class Set implements Snippet
13
{
14
    use
15
        EscaperAware,
16
        TypeGuesser;
17
18
    private
19
        $sets;
20
21 8
    public function __construct()
22
    {
23 8
        $this->sets = array();
24 8
    }
25
26 7
    public function set(array $fields)
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...
27
    {
28 7
        $this->sets = array_merge($this->sets, $fields);
29
30 7
        return $this;
31
    }
32
33 7
    public function toString()
34
    {
35 7
        if(empty($this->sets))
36 7
        {
37 1
            return '';
38
        }
39
40 6
        $sets = array();
41 6
        foreach($this->sets as $columnName => $value)
42
        {
43 6
            $type = $this->guessType($columnName, $value);
44
45 6
            $sets[] = (new Conditions\Equal($type, $value))->toString($this->escaper);
46 6
        }
47
48 6
        return sprintf('SET %s', implode(', ', $sets));
49
    }
50
}
51