Completed
Push — master ( 03a8c3...2d8113 )
by Peter
02:49
created

Configuration::getTotalPages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
namespace AnimeDb\Bundle\PaginationBundle\Service;
10
11
/**
12
 * @author Peter Gribanov <[email protected]>
13
 */
14
class Configuration
15
{
16
    /**
17
     * Length of the list of pagination defaults.
18
     *
19
     * @var int
20
     */
21
    const DEFAULT_LIST_LENGTH = 5;
22
23
    /**
24
     * @var int
25
     */
26
    const DEFAULT_PAGE_LINK = '%s';
27
28
    /**
29
     * @var int
30
     */
31
    protected $total_pages = 0;
32
33
    /**
34
     * @var int
35
     */
36
    protected $current_page = 1;
37
38
    /**
39
     * @var View
40
     */
41
    protected $view;
42
43
    /**
44
     * The number of pages displayed in the navigation.
45
     *
46
     * @var int
47
     */
48
    protected $max_navigate = self::DEFAULT_LIST_LENGTH;
49
50
    /**
51
     * @var string|callback
52
     */
53
    protected $page_link = self::DEFAULT_PAGE_LINK;
54
55
    /**
56
     * @var string
57
     */
58
    protected $first_page_link = '';
59
60
    /**
61
     * @param int $total_pages
62
     * @param int $current_page
63
     */
64 15
    public function __construct($total_pages = 0, $current_page = 1)
65
    {
66 15
        $this->setCurrentPage($current_page);
67 15
        $this->setTotalPages($total_pages);
68 15
    }
69
70
    /**
71
     * @param int $total_pages
72
     * @param int $current_page
73
     *
74
     * @return Configuration
75
     */
76 2
    public static function create($total_pages = 0, $current_page = 1)
77
    {
78 2
        return new static($total_pages, $current_page);
79
    }
80
81
    /**
82
     * @return int
83
     */
84 9
    public function getTotalPages()
85
    {
86 9
        return $this->total_pages;
87
    }
88
89
    /**
90
     * @param int $total_pages
91
     *
92
     * @return Configuration
93
     */
94 15
    public function setTotalPages($total_pages)
95
    {
96 15
        $this->total_pages = $total_pages;
97
98 15
        return $this;
99
    }
100
101
    /**
102
     * @return int
103
     */
104 9
    public function getCurrentPage()
105
    {
106 9
        return $this->current_page;
107
    }
108
109
    /**
110
     * @param int $current_page
111
     *
112
     * @return Configuration
113
     */
114 15
    public function setCurrentPage($current_page)
115
    {
116 15
        $this->current_page = $current_page;
117
118 15
        return $this;
119
    }
120
121
    /**
122
     * @return int
123
     */
124 5
    public function getMaxNavigate()
125
    {
126 5
        return $this->max_navigate;
127
    }
128
129
    /**
130
     * @param int $max_navigate
131
     *
132
     * @return Configuration
133
     */
134 5
    public function setMaxNavigate($max_navigate)
135
    {
136 5
        $this->max_navigate = $max_navigate;
137
138 5
        return $this;
139
    }
140
141
    /**
142
     * @return string|callback
143
     */
144 2
    public function getPageLink()
145
    {
146 2
        return $this->page_link;
147
    }
148
149
    /**
150
     * Set page link.
151
     *
152
     * Basic reference, for example `page_%s.html` where %s page number, or
153
     * callback function which takes one parameter - the number of the page.
154
     *
155
     * <code>
156
     * function ($number) {
157
     *     return 'page_'.$number.'.html';
158
     * }
159
     * </code>
160
     *
161
     * @param string|callback $page_link
162
     *
163
     * @return Configuration
164
     */
165 3
    public function setPageLink($page_link)
166
    {
167 3
        $this->page_link = $page_link;
168
169 3
        return $this;
170
    }
171
172
    /**
173
     * @return string
174
     */
175 1
    public function getFirstPageLink()
176
    {
177 1
        return $this->first_page_link;
178
    }
179
180
    /**
181
     * @param string $first_page_link
182
     *
183
     * @return Configuration
184
     */
185 1
    public function setFirstPageLink($first_page_link)
186
    {
187 1
        $this->first_page_link = $first_page_link;
188
189 1
        return $this;
190
    }
191
192
    /**
193
     * @return View
194
     */
195 1
    public function getView()
196
    {
197 1
        if (!$this->view) {
198 1
            $this->view = new View($this, new NavigateRange($this));
199 1
        }
200
201 1
        return $this->view;
202
    }
203
}
204