Update   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 44
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A update() 0 4 1
A getSql() 0 7 1
1
<?php
2
3
/**
4
 * Bluz Framework Component
5
 *
6
 * @copyright Bluz PHP Team
7
 * @link      https://github.com/bluzphp/framework
8
 */
9
10
declare(strict_types=1);
11
12
namespace Bluz\Db\Query;
13
14
use Bluz\Proxy\Db;
15
16
/**
17
 * Builder of UPDATE queries
18
 *
19
 * @package Bluz\Db\Query
20
 */
21
class Update extends AbstractBuilder
22
{
23
    use Traits\Set;
24
    use Traits\Where;
25
    use Traits\Limit;
26
27
    /**
28
     * @var string Table name
29
     */
30
    protected $table;
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 1
    public function getSql(): string
36
    {
37
        return 'UPDATE '
38 1
            . Db::quoteIdentifier($this->table)
39 1
            . $this->prepareSet()
40 1
            . $this->prepareWhere()
41 1
            . $this->prepareLimit();
42
    }
43
44
    /**
45
     * Turns the query being built into a bulk update query that ranges over
46
     * a certain table
47
     *
48
     * Example
49
     * <code>
50
     *     $ub = new UpdateBuilder();
51
     *     $ub
52
     *         ->update('users')
53
     *         ->set('password', md5('password'))
54
     *         ->where('id = ?');
55
     * </code>
56
     *
57
     * @param  string $table the table whose rows are subject to the update
58
     *
59
     * @return Update instance
60
     */
61 2
    public function update($table): Update
62
    {
63 2
        $this->table = $table;
64 2
        return $this;
65
    }
66
}
67