Passed
Branch develop (f4dbb7)
by compolom
02:00
created

Update::values()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php declare(strict_types=1);
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
    protected $values = null;
24
25
    public function set(array $values): string
26
    {
27
        return $this->concat(
28
            array_map(function ($field, $value) {
29
                return $field . ' = ' . $value;
30
            },
31
                $this->escapeField($this->fields), $this->preSet($values, 'u')));
32
    }
33
34
    public function values(array $values): Insert
35
    {
36
        $this->values = $this->set($values);
37
        return $this;
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function get(): string
44
    {
45
        $this->addPlaceholders($this->placeholders()->get());
46
        return 'UPDATE ' . $this->table() . ' SET '
47
            . (!is_null($this->values)
48
                ? $this->values
49
                : $this->concat(array_map(function ($field) {
50
                    return $this->escapeField($field) . ' = ?';;
51
                }, $this->fields))
52
            )
53
            . $this->getParts();
54
    }
55
}
56