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

Update   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A statement() 0 3 1
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