Completed
Push — master ( 04a99a...21cf60 )
by Denis
01:21
created

ArrayDataProvider::getCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Woo\GridView\DataProviders;
4
5
class ArrayDataProvider implements DataProviderInterface
6
{
7
    /**
8
     * @var array
9
     */
10
    private $data;
11
12
    public function __construct(array $data)
13
    {
14
        $this->data = $data;
15
    }
16
17
    /**
18
     * Should return total amount of rows
19
     * @return int
20
     */
21
    public function getCount() : int
22
    {
23
        return count($this->data);
24
    }
25
26
    /**
27
     * Should return amount of pages
28
     * @param int $perPage - amount of records per page
29
     * @return int
30
     */
31
    public function getTotalPages(int $perPage) : int
32
    {
33
        return ceil($this->getCount() / $perPage);
34
    }
35
36
    /**
37
     * Should return a list of data for current page
38
     * @param int $page
39
     * @param int $perPage - amount of records per page
40
     * @return mixed
41
     */
42
    public function getData(int $page, int $perPage)
43
    {
44
        return array_splice($this->data, ($page -1) * $perPage, $perPage);
45
    }
46
}