Completed
Push — master ( 037c01...3910ea )
by Oscar
01:42
created

Update::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace SimpleCrud\Queries;
5
6
use SimpleCrud\Table;
7
8
final class Update extends Query
9
{
10
    use Traits\HasRelatedWith;
11
12
    protected const ALLOWED_METHODS = [
13
        'set',
14
        'setFlag',
15
        'where',
16
        'orWhere',
17
        'catWhere',
18
        'orderBy',
19
        'limit',
20
        'offset',
21
    ];
22
23
    public function __construct(Table $table, array $data = [])
24
    {
25
        $this->table = $table;
26
27
        $this->query = $table->getDatabase()
28
            ->update()
29
            ->table((string) $table);
30
31
        foreach ($data as $fieldName => $value) {
32
            $this->table->{$fieldName}->update($this->query, $value);
33
        }
34
    }
35
}
36