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

LimitTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 46
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A limit() 0 5 1
A getLimit() 0 4 1
A buildLimit() 0 7 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