Limit   A
last analyzed

Complexity

Total Complexity 29

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%
Metric Value
dl 0
loc 56
wmc 29
lcom 1
cbo 2
ccs 28
cts 28
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A limit() 0 6 1
A offset() 0 11 2
A buildLimit() 0 14 2
A buildLimitClause() 0 7 2
A buildOffsetClause() 0 7 2
1
<?php
2
3
namespace Muffin\Queries\Snippets\Builders;
4
5
use Muffin\Queries\Snippets;
6
7
trait Limit
8
{
9
    protected
10
        $limit,
11
        $offset;
12
13 7
    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...
14
    {
15 7
        $this->limit = new Snippets\Limit($limit);
16
17 7
        return $this;
18
    }
19
20 6
    public function offset($offset)
21
    {
22 6
        if(!$this->limit instanceof Snippets\Limit)
23 6
        {
24 1
            throw new \LogicException('LIMIT is required to define OFFSET.');
25
        }
26
27 5
        $this->offset = new Snippets\Offset($offset);
28
29 5
        return $this;
30
    }
31
32 30
    private function buildLimit()
33
    {
34 30
        $limit = $this->buildLimitClause();
35
36 30
        $offset = '';
37 30
        if(! empty($limit))
38 30
        {
39 6
            $offset = $this->buildOffsetClause();
40 6
        }
41
42 30
        $clauses = array($limit, $offset);
43
44 30
        return implode(' ', array_filter($clauses));
45
    }
46
47 30
    private function buildLimitClause()
48
    {
49 30
        if($this->limit instanceof Snippets\Limit)
50 30
        {
51 7
            return $this->limit->toString();
52
        }
53 25
    }
54
55 6
    private function buildOffsetClause()
56
    {
57 6
        if($this->offset instanceof Snippets\Offset)
58 6
        {
59 4
            return $this->offset->toString();
60
        }
61 2
    }
62
}
63