Completed
Push — 2.0 ( 1160ec...acba87 )
by Vermeulen
05:15
created

Limit   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 68
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRowCount() 0 4 1
A getOffset() 0 4 1
A __invoke() 0 9 2
A generate() 0 10 3
1
<?php
2
3
namespace BfwSql\Queries\Parts;
4
5
class Limit extends AbstractPart
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    protected $partPrefix = 'LIMIT';
11
    
12
    /**
13
     * @var integer|null $rowCount The maximum number of rows to return
14
     */
15
    protected $rowCount = null;
16
    
17
    /**
18
     * @var integer|null $offset The offset of the first row to return
19
     */
20
    protected $offset = null;
21
    
22
    /**
23
     * Getter accessor to property rowCount
24
     * 
25
     * @return integer|null
26
     */
27
    public function getRowCount()
28
    {
29
        return $this->rowCount;
30
    }
31
32
    /**
33
     * Getter accessor to property offset
34
     * 
35
     * @return integer|null
36
     */
37
    public function getOffset()
38
    {
39
        return $this->offset;
40
    }
41
    
42
    /**
43
     * Magic method __invoke, used when the user call object like a function
44
     * @link http://php.net/manual/en/language.oop5.magic.php#object.invoke
45
     * 
46
     * @param integer|array $limitInfos If it's a integer, the number of row to
47
     *  return. If an array, the format is [offset, rowCount]
48
     */
49
    public function __invoke(...$limitInfos)
50
    {
51
        if (isset($limitInfos[1])) {
52
            $this->offset   = (int) $limitInfos[0];
53
            $this->rowCount = (int) $limitInfos[1];
54
        } else {
55
            $this->rowCount = (int) $limitInfos[0];
56
        }
57
    }
58
    
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function generate(): string
63
    {
64
        if ($this->rowCount === null) {
65
            return '';
66
        } else if ($this->offset === null) {
67
            return (string) $this->rowCount;
68
        } else {
69
            return $this->offset.', '.$this->rowCount;
70
        }
71
    }
72
}
73