Passed
Push — main ( c0dd4f...6fb54d )
by Peter
02:57
created

Update   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 67
ccs 22
cts 22
cp 1
rs 10
c 1
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 8 1
A modifier() 0 14 4
A limit() 0 5 1
A getLimit() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace QB\MySQL\Statement;
6
7
use QB\Generic\Statement\Update as GenericUpdate;
8
9
class Update extends GenericUpdate
10
{
11
    public const LOW_PRIORITY  = 'LOW_PRIORITY';
12
    public const IGNORE        = 'IGNORE';
13
14
    /** @var array<int,string> */
15
    protected array $modifiers = [];
16
17
    protected ?int $limit = null;
18
19
    /**
20
     * @param string ...$modifiers
21
     *
22
     * @return $this
23
     */
24 1
    public function modifier(string ...$modifiers): static
25
    {
26 1
        foreach ($modifiers as $modifier) {
27
            switch ($modifier) {
28 1
                case static::LOW_PRIORITY:
29 1
                    $this->modifiers[0] = $modifier;
30 1
                    break;
31 1
                case static::IGNORE:
32 1
                    $this->modifiers[1] = $modifier;
33 1
                    break;
34
            }
35
        }
36
37 1
        return $this;
38
    }
39
40
    /**
41
     * @param int|null $limit
42
     *
43
     * @return $this
44
     */
45 1
    public function limit(?int $limit): static
46
    {
47 1
        $this->limit = $limit;
48
49 1
        return $this;
50
    }
51
52
    /**
53
     * @return string
54
     */
55 3
    public function __toString(): string
56
    {
57 3
        $parts = array_merge(
58 3
            [parent::__toString()],
59 2
            $this->getLimit(),
60
        );
61
62 2
        return implode(PHP_EOL, $parts);
63
    }
64
65
    /**
66
     * @return string[]
67
     */
68 2
    protected function getLimit(): array
69
    {
70 2
        $parts = [];
71 2
        if ($this->limit !== null) {
72 1
            $parts[] = 'LIMIT ' . $this->limit;
73
        }
74
75 2
        return $parts;
76
    }
77
}
78