Limit::limit()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 6
rs 10
1
<?php
2
3
namespace mindplay\sql\model\components;
4
5
use InvalidArgumentException;
6
7
/**
8
 * This trait implements the stand-alone `LIMIT` clause (without `OFFSET`) supported
9
 * by the MySQL `UPDATE` and `DELETE` query-builders.
10
 */
11
trait Limit
12
{
13
    protected int|null $limit = null;
14
15
    /**
16
     * @param int $limit max. number of records
17
     *
18
     * @return $this
19
     *
20
     * @throws InvalidArgumentException if the given limit is less than 1
21
     */
22
    public function limit($limit): static
23
    {
24
        if ($limit < 1) {
25
            throw new InvalidArgumentException("limit out of range: {$limit}");
26
        }
27
28
        $this->limit = $limit;
29
30
        return $this;
31
    }
32
}
33