Limit   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 66
c 0
b 0
f 0
wmc 9
lcom 1
cbo 2
ccs 23
cts 23
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 9 2
A buildOffsetClause() 0 9 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Puzzle\QueryBuilder\Queries\Snippets\Builders;
6
7
use Puzzle\QueryBuilder\Queries\Snippets;
8
9
trait Limit
10
{
11
    protected
12
        $limit,
1 ignored issue
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $limit.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
13
        $offset;
14
15
    /**
16
     * @param int|string $limit
17
     */
18 7
    public function limit($limit): self
19
    {
20 7
        $this->limit = new Snippets\Limit($limit);
21
22 7
        return $this;
23
    }
24
25
    /**
26
     * @param int|string $offset
27
     */
28 6
    public function offset($offset): self
29
    {
30 6
        if(!$this->limit instanceof Snippets\Limit)
31
        {
32 1
            throw new \LogicException('LIMIT is required to define OFFSET.');
33
        }
34
35 5
        $this->offset = new Snippets\Offset($offset);
36
37 5
        return $this;
38
    }
39
40 30
    private function buildLimit(): string
41
    {
42 30
        $limit = $this->buildLimitClause();
43
44 30
        $offset = '';
45 30
        if(! empty($limit))
46
        {
47 6
            $offset = $this->buildOffsetClause();
48
        }
49
50 30
        $clauses = array($limit, $offset);
51
52 30
        return implode(' ', array_filter($clauses));
53
    }
54
55 30
    private function buildLimitClause(): string
56
    {
57 30
        if($this->limit instanceof Snippets\Limit)
58
        {
59 7
            return $this->limit->toString();
60
        }
61
62 25
        return '';
63
    }
64
65 6
    private function buildOffsetClause(): string
66
    {
67 6
        if($this->offset instanceof Snippets\Offset)
68
        {
69 4
            return $this->offset->toString();
70
        }
71
72 2
        return '';
73
    }
74
}
75