Completed
Pull Request — master (#90)
by Arnaud
02:00
created

PagerfantaAdminAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 80
ccs 0
cts 25
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSlice() 0 6 1
A __construct() 0 11 1
A getNbResults() 0 7 1
A retrieveData() 0 7 1
1
<?php
2
3
namespace LAG\AdminBundle\Pager;
4
5
use LAG\AdminBundle\DataProvider\DataProviderInterface;
6
use Pagerfanta\Adapter\AdapterInterface;
7
8
class PagerfantaAdminAdapter implements AdapterInterface
9
{
10
    /**
11
     * @var DataProviderInterface
12
     */
13
    private $dataProvider;
14
15
    /**
16
     * @var array
17
     */
18
    private $criteria;
19
20
    /**
21
     * @var array
22
     */
23
    private $orderBy;
24
    
25
    /**
26
     * @var array
27
     */
28
    private $options;
29
    
30
    private $data;
31
    
32
    /**
33
     * PagerfantaAdminAdapter constructor.
34
     *
35
     * @param DataProviderInterface $dataProvider
36
     * @param array                 $criteria
37
     * @param array                 $orderBy
38
     * @param array                 $options
39
     */
40
    public function __construct(
41
        DataProviderInterface $dataProvider,
42
        array $criteria = [],
43
        array $orderBy = [],
44
        array $options = []
45
    ) {
46
        $this->dataProvider = $dataProvider;
47
        $this->criteria = $criteria;
48
        $this->orderBy = $orderBy;
49
        $this->options = $options;
50
    }
51
52
    /**
53
     * Returns the number of results.
54
     *
55
     * @return integer The number of results.
56
     */
57
    public function getNbResults()
58
    {
59
        return $this
60
            ->dataProvider
61
            ->count($this->criteria)
62
        ;
63
    }
64
    
65
    /**
66
     * Returns an slice of the results.
67
     *
68
     * @param integer $offset The offset.
69
     * @param integer $length The length.
70
     *
71
     * @return array|\Traversable The slice.
72
     */
73
    public function getSlice($offset, $length)
74
    {
75
        $this->retrieveData($length, $offset);
76
    
77
        return $this->data;
78
    }
79
    
80
    private function retrieveData($length, $offset)
81
    {
82
        $this->data = $this
83
            ->dataProvider
84
            ->findBy($this->criteria, $this->orderBy, $length, $offset)
85
        ;
86
    }
87
}
88