Configuration::getView()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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