Set   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 39
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A set() 0 6 1
A toString() 0 17 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Puzzle\QueryBuilder\Queries\Snippets;
6
7
use Puzzle\QueryBuilder\Snippet;
8
use Puzzle\QueryBuilder\Type;
9
use Puzzle\QueryBuilder\Conditions;
10
use Puzzle\QueryBuilder\Traits\EscaperAware;
11
use Puzzle\QueryBuilder\Traits\TypeGuesser;
12
13
class Set implements Snippet
14
{
15
    use
16
        EscaperAware,
17
        TypeGuesser;
18
19
    private
20
        $sets;
1 ignored issue
show
Coding Style introduced by
The visibility should be declared for property $sets.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
21
22 8
    public function __construct()
23
    {
24 8
        $this->sets = [];
25 8
    }
26
27 7
    public function set(array $fields): self
28
    {
29 7
        $this->sets = array_merge($this->sets, $fields);
30
31 7
        return $this;
32
    }
33
34 7
    public function toString(): string
35
    {
36 7
        if(empty($this->sets))
37
        {
38 1
            return '';
39
        }
40
41 6
        $sets = array();
42 6
        foreach($this->sets as $columnName => $value)
43
        {
44 6
            $type = $this->guessType($columnName, $value);
45
46 6
            $sets[] = (new Conditions\Equal($type, $value))->toString($this->escaper);
47
        }
48
49 6
        return sprintf('SET %s', implode(', ', $sets));
50
    }
51
}
52