Paginator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSlice() 0 3 1
A getNbResults() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: goldoni
6
 * Date: 05.11.18
7
 * Time: 00:46.
8
 */
9
10
namespace Goldoni\Builder;
11
12
use Pagerfanta\Adapter\AdapterInterface;
13
14
/**
15
 * Class Paginator.
16
 */
17
class Paginator implements AdapterInterface
18
{
19
    /**
20
     * @var \Goldoni\Builder\Query
21
     */
22
    private $query;
23
24
    /**
25
     * Paginator constructor.
26
     *
27
     * @param \Goldoni\Builder\Query $query
28
     */
29
    public function __construct(Query $query)
30
    {
31
        $this->query = $query;
32
    }
33
34
    /**
35
     * Returns the number of results.
36
     *
37
     * @throws \Exception
38
     *
39
     * @return int the number of results
40
     */
41
    public function getNbResults()
42
    {
43
        return $this->query->count();
44
    }
45
46
    /**
47
     * Returns an slice of the results.
48
     *
49
     * @param int $offset the offset
50
     * @param int $length the length
51
     *
52
     * @return array|\Traversable the slice
53
     */
54
    public function getSlice($offset, $length)
55
    {
56
        return $this->query->limit($length, $offset)->fetchAll();
57
    }
58
}
59