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

BaseDataProvider::getTotalPages()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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
}