Completed
Push — master ( f11337...38bba2 )
by Kevin
02:15
created

Pager   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 89
ccs 19
cts 19
cp 1
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getNextPage() 0 10 2
A getPreviousPage() 0 10 2
A getFirstPage() 0 4 1
A getLastPage() 0 10 2
A pagesCount() 0 4 1
getCurrentPage() 0 1 ?
getLimit() 0 1 ?
count() 0 1 ?
totalCount() 0 1 ?
getResults() 0 1 ?
1
<?php
2
3
namespace Zenstruck\Porpaginas;
4
5
/**
6
 * @author Kevin Bond <[email protected]>
7
 */
8
abstract class Pager implements \Countable
9
{
10
    /**
11
     * @return int|null
12
     */
13 11
    final public function getNextPage()
14
    {
15 11
        $currentPage = $this->getCurrentPage();
16
17 11
        if ($currentPage === $this->getLastPage()) {
18 7
            return null;
19
        }
20
21 4
        return ++$currentPage;
22
    }
23
24
    /**
25
     * @return int|null
26
     */
27 11
    final public function getPreviousPage()
28
    {
29 11
        $page = $this->getCurrentPage();
30
31 11
        if ($page === 1) {
32 6
            return null;
33
        }
34
35 5
        return --$page;
36
    }
37
38
    /**
39
     * @return int
40
     */
41 11
    final public function getFirstPage()
42
    {
43 11
        return 1;
44
    }
45
46
    /**
47
     * @return int
48
     */
49 12
    final public function getLastPage()
50
    {
51 12
        $totalCount = $this->totalCount();
52
53 12
        if ($totalCount === 0) {
54 3
            return 1;
55
        }
56
57 9
        return (int) ceil($totalCount / $this->getLimit());
58
    }
59
60
    /**
61
     * @return int
62
     */
63 6
    final public function pagesCount()
64
    {
65 6
        return $this->getLastPage();
66
    }
67
68
    /**
69
     * @return int
70
     */
71
    abstract public function getCurrentPage();
72
73
    /**
74
     * @return int
75
     */
76
    abstract public function getLimit();
77
78
    /**
79
     * The result count for the current page.
80
     *
81
     * @return int
82
     */
83
    abstract public function count();
84
85
    /**
86
     * The total result count.
87
     *
88
     * @return int
89
     */
90
    abstract public function totalCount();
91
92
    /**
93
     * @return Page
94
     */
95
    abstract public function getResults();
96
}
97