Update::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Compolomus\LSQLQueryBuilder\Parts;
4
5
use Compolomus\LSQLQueryBuilder\System\Traits\{
6
    Helper,
7
    Caller,
8
    GetParts,
9
    Placeholders,
10
    Limit as TLimit,
11
    Where as TWhere,
12
    Order as TOrder
13
};
14
15
/**
16
 * @method string table()
17
 * @method void addPlaceholders($placeholders)
18
 */
19
class Update extends Insert
20
{
21
    use Caller, TLimit, TWhere, TOrder, GetParts, Placeholders, Helper;
22
23
    public function __construct(array $args = [])
24
    {
25
        parent::__construct($args);
26
        $this->values = null;
0 ignored issues
show
Documentation Bug introduced by
It seems like null of type null is incompatible with the declared type array of property $values.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
    }
28
29
    public function set(array $values): string
30
    {
31
        return $this->concat(
32
            array_map(function ($field, $value) {
33
                return $field . ' = ' . $value;
34
            },
35
                $this->escapeField($this->fields), $this->preSet($values, 'u')));
36
    }
37
38
    public function values(array $values): Insert
39
    {
40
        $this->values = $this->set($values);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->set($values) of type string is incompatible with the declared type array of property $values.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
        return $this;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function get(): string
48
    {
49
        $this->addPlaceholders($this->placeholders()->get());
50
        return 'UPDATE ' . $this->table() . ' SET '
51
            . ($this->values ??
52
                $this->concat(array_map(function ($field) {
53
                    return $this->escapeField($field) . ' = ?';
54
                }, $this->fields))
55
            )
56
            . $this->getParts();
57
    }
58
}
59