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

Update::limit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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