Completed
Push — 3.x ( 9be43c...53c3d5 )
by Paul
03:10 queued 01:24
created

LimitTrait::getLimit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\SqlQuery\Common;
10
11
/**
12
 *
13
 * A trait for LIMIT clauses.
14
 *
15
 * @package Aura.SqlQuery
16
 *
17
 */
18
trait LimitTrait
19
{
20
    private $limit = 0;
21
22
    /**
23
     *
24
     * Sets a limit count on the query.
25
     *
26
     * @param int $limit The number of rows to select.
27
     *
28
     * @return $this
29
     *
30
     */
31 55
    public function limit($limit)
32
    {
33 55
        $this->limit = (int) $limit;
34 55
        return $this;
35
    }
36
37
    /**
38
     *
39
     * Returns the LIMIT value.
40
     *
41
     * @return int
42
     *
43
     */
44 208
    public function getLimit()
45
    {
46 208
        return $this->limit;
47
    }
48
49
    /**
50
     *
51
     * Builds the `LIMIT` clause of the statement.
52
     *
53
     * @return string
54
     *
55
     */
56 9
    protected function buildLimit()
57
    {
58 9
        if (empty($this->limit)) {
59 5
            return '';
60
        }
61 4
        return PHP_EOL . "LIMIT {$this->limit}";
62
    }
63
}
64