Completed
Pull Request — master (#3)
by Denis
01:34
created

BaseDataProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
getCount() 0 1 ?
getData() 0 1 ?
A getTotalPages() 0 8 2
1
<?php
2
3
namespace Woo\GridView\DataProviders;
4
5
abstract class BaseDataProvider
6
{
7
    /**
8
     * Should return total amount of rows
9
     * @return int
10
     */
11
    abstract public function getCount() : int;
12
13
    /**
14
     * Should return a list of data for current page
15
     * @param array $filters
16
     * @param string $orderBy
17
     * @param string $orderSort
18
     * @param int $page
19
     * @param int $perPage - amount of records per page
20
     * @return mixed
21
     */
22
    abstract public function getData(array $filters, string $orderBy, string $orderSort, int $page, int $perPage);
23
24
    /**
25
     * Allows to get amount of found pages
26
     */
27
    public function getTotalPages(int $perPage): int
28
    {
29
        if ($perPage == 0) {
30
            return 1;
31
        }
32
33
        return ceil($this->getCount() / $perPage);
34
    }
35
36
}