Complex classes like TelegramInlineView often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TelegramInlineView, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class TelegramInlineView implements ViewInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var TelegramInlineTemplate |
||
12 | */ |
||
13 | private $template; |
||
14 | |||
15 | /** |
||
16 | * @var PagerfantaInterface |
||
17 | */ |
||
18 | private $pagerfanta; |
||
19 | |||
20 | private $currentPage; |
||
21 | private $nbPages; |
||
22 | |||
23 | private $startPage; |
||
24 | private $endPage; |
||
25 | private $maxPerPage; |
||
26 | |||
27 | private $buttons; |
||
28 | |||
29 | private $maxButtons; |
||
30 | |||
31 | 10 | public function __construct(TemplateInterface $template = null) |
|
36 | |||
37 | 10 | protected function createDefaultTemplate() |
|
41 | |||
42 | 10 | public function render(PagerfantaInterface $pagerfanta, $routeGenerator, array $options = array()) |
|
51 | |||
52 | 10 | private function initializePagerfanta(PagerfantaInterface $pagerfanta) |
|
60 | |||
61 | 10 | private function initializeOptions($options) |
|
67 | |||
68 | 9 | protected function getDefaultProximity() |
|
78 | |||
79 | 10 | private function configureTemplate($routeGenerator, $options) |
|
84 | |||
85 | 10 | private function generatePages() |
|
99 | |||
100 | 10 | private function calculateStartAndEndPage() |
|
118 | |||
119 | 10 | private function startPageUnderflow($startPage) |
|
123 | |||
124 | 10 | private function endPageOverflow($endPage) |
|
128 | |||
129 | 2 | private function calculateEndPageForStartPageUnderflow($startPage, $endPage) |
|
133 | |||
134 | 1 | private function calculateStartPageForEndPageOverflow($startPage, $endPage) |
|
138 | |||
139 | 10 | private function previous() |
|
151 | |||
152 | 10 | private function first() |
|
164 | |||
165 | 10 | private function pages() |
|
175 | |||
176 | 10 | private function page($page) |
|
188 | |||
189 | 10 | private function pushNewButton(array $params) { |
|
195 | |||
196 | private function pageOfPreviousButton() |
||
202 | |||
203 | 10 | private function pageExists($page) { |
|
206 | |||
207 | private function toLast($n) |
||
211 | |||
212 | 10 | private function last() |
|
232 | |||
233 | 10 | private function next() |
|
251 | |||
252 | public function setMaxButtons($max) |
||
256 | |||
257 | /** |
||
258 | * {@inheritdoc} |
||
259 | */ |
||
260 | public function getName() |
||
264 | |||
265 | |||
266 | /** |
||
267 | * Convert the collection to its string representation. |
||
268 | * |
||
269 | * @return string |
||
270 | */ |
||
271 | 10 | public function __toString() |
|
275 | } |
||
276 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..