Completed
Push — master ( 755d2f...4eddf0 )
by Christopher
05:22
created

LimitMethod   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 31
wmc 9
lcom 1
cbo 0
ccs 0
cts 10
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A limit() 0 12 2
cloneWith() 0 1 ?
1
<?php
2
3
namespace AsyncPHP\Icicle\Database\Builder\Method;
4
5
use Aura\SqlQuery\Common\LimitOffsetInterface;
6
use LogicException;
7
8
/**
9
 * @property string $table
10
 * @property LimitOffsetInterface $query
11
 */
12
trait LimitMethod
13
{
14
    /**
15
     * @param int $limit
16
     * @param int $offset
17
     *
18
     * @return static
19
     *
20
     * @throws LogicException
21
     */
22
    public function limit($limit, $offset = 0)
23
    {
24
        if (!isset($this->query)) {
25
            throw new LogicException("limit() called before select()");
26
        }
27
28
        $query = clone $this->query;
29
        $query->limit($limit);
30
        $query->offset($offset);
31
32
        return $this->cloneWith("query", $query);
33
    }
34
35
    /**
36
     * @param string $key
37
     * @param mixed $value
38
     *
39
     * @return static
40
     */
41
    abstract protected function cloneWith($key, $value);
42
}
43