Set::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
namespace HexMakina\Crudites\Grammar\Clause;
4
5
use HexMakina\Crudites\Grammar\Predicate;
6
7
class Set extends Clause
8
{
9
    protected string $alterations = '';
10
11
    public function __construct(array $alterations)
12
    {
13
        parent::__construct();
14
        foreach ($alterations as $field_name => $value) {
15
            $predicate = (new Predicate([$field_name], '='))->withValue($value, 'set_'.$field_name);
16
            
17
            $this->alterations .= $predicate->__toString().',';
18
            $this->bindings = array_merge($this->bindings, $predicate->bindings());
19
        }
20
    }
21
22
    public function __toString(): string
23
    {
24
        return 'SET ' . rtrim($this->alterations, ',');
25
    }
26
27
    public function name(): string
28
    {
29
        return self::SET;
30
    }
31
}