Completed
Pull Request — 3.x (#120)
by
unknown
01:47
created

LimitTrait::buildLimit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
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 50
    public function limit($limit)
32
    {
33 50
        $this->limit = (int) $limit;
34 50
        return $this;
35
    }
36
37
    /**
38
     *
39
     * Returns the LIMIT value.
40
     *
41
     * @return int
42
     *
43
     */
44 203
    public function getLimit()
45
    {
46 203
        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