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

Pager::getPreviousPage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 2
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