Completed
Push — master ( 509987...79a3d2 )
by Rasmus
02:45
created

Limit::limit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 5
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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
    /**
14
     * @var int|null
15
     */
16
    protected $limit;
17
18
    /**
19
     * @param int $limit max. number of records
20
     *
21
     * @return $this
22
     *
23
     * @throws InvalidArgumentException if the given limit is less than 1
24
     */
25
    public function limit($limit)
0 ignored issues
show
Best Practice introduced by
Using PHP4-style constructors that are named like the class is not recommend; better use the more explicit __construct method.
Loading history...
26
    {
27
        if ($limit < 1) {
28
            throw new InvalidArgumentException("limit out of range: {$limit}");
29
        }
30
31
        $this->limit = $limit;
32
33
        return $this;
34
    }
35
}
36