Passed
Push — main ( 303b6c...b49db2 )
by Sammy
01:47 queued 15s
created

Update::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 3
dl 0
loc 13
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace HexMakina\Crudites\Grammar\Query;
4
5
use HexMakina\Crudites\Grammar\Clause\Where;
6
use HexMakina\Crudites\Grammar\Clause\Set;
7
8
9
class Update extends Query
10
{
11
    public function __construct(string $table, array $alterations, array $conditions)
12
    {
13
        if (empty($alterations) || empty($conditions)) {
14
            throw new \InvalidArgumentException('EMPTY_ALTERATIONS_OR_CONDITIONS');
15
        }
16
17
        $this->table = $table;
18
        
19
        $this->add(new Set($alterations));
20
21
        $clause = new Where($table);
22
        $clause->andFields($conditions, $table, '=');
23
        $this->add($clause);
24
    }
25
26
    public function statement(): string
27
    {
28
        return sprintf('UPDATE `%s` %s %s;', $this->table, $this->clause(Set::SET), $this->clause(Where::WHERE));
29
    }
30
}
31