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() |
|
| 173 | |||
| 174 | 10 | private function page($page) |
|
| 186 | |||
| 187 | 10 | private function pushNewButton(array $params) { |
|
| 193 | |||
| 194 | private function pageOfPreviousButton() |
||
| 200 | |||
| 201 | 10 | private function pageExists($page) { |
|
| 204 | |||
| 205 | private function toLast($n) |
||
| 209 | |||
| 210 | 10 | private function last() |
|
| 230 | |||
| 231 | 10 | private function next() |
|
| 249 | |||
| 250 | public function setMaxButtons($max) |
||
| 254 | |||
| 255 | /** |
||
| 256 | * {@inheritdoc} |
||
| 257 | */ |
||
| 258 | public function getName() |
||
| 262 | |||
| 263 | |||
| 264 | /** |
||
| 265 | * Convert the collection to its string representation. |
||
| 266 | * |
||
| 267 | * @return string |
||
| 268 | */ |
||
| 269 | 10 | public function __toString() |
|
| 273 | } |
||
| 274 |
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..