Complex classes like PageManager 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 PageManager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class PageManager extends TrackingManager |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * The relative (to the stakx project) file path to the redirect template |
||
| 28 | * |
||
| 29 | * @var string|bool |
||
| 30 | */ |
||
| 31 | private $redirectTemplate; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var ContentItem[][] |
||
| 35 | */ |
||
| 36 | private $collections; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var Folder |
||
| 40 | */ |
||
| 41 | private $targetDir; |
||
| 42 | |||
| 43 | private $siteMenu; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var \Twig_Environment |
||
| 47 | */ |
||
| 48 | private $twig; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * PageManager constructor |
||
| 52 | */ |
||
| 53 | 1 | public function __construct() |
|
| 59 | |||
| 60 | public function setCollections (&$collections) |
||
| 66 | |||
| 67 | 1 | public function setRedirectTemplate ($filePath) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * @param Folder $folder The relative target directory as specified from the configuration file |
||
| 74 | */ |
||
| 75 | 1 | public function setTargetFolder (&$folder) |
|
| 79 | |||
| 80 | 1 | public function configureTwig ($configuration, $options) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * An array representing the website's menu structure with children and grandchildren made from static PageViews |
||
| 90 | * |
||
| 91 | * @return array |
||
| 92 | */ |
||
| 93 | public function getSiteMenu () |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Go through all of the PageView directories and create a respective PageView for each and classify them as a |
||
| 100 | * dynamic or static PageView. |
||
| 101 | * |
||
| 102 | * @param $pageViewFolders |
||
| 103 | */ |
||
| 104 | 1 | public function parsePageViews ($pageViewFolders) |
|
| 130 | |||
| 131 | /** |
||
| 132 | * Compile dynamic and static PageViews |
||
| 133 | */ |
||
| 134 | 1 | public function compileAll () |
|
| 141 | |||
| 142 | public function compileSome ($filter = array()) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param ContentItem $contentItem |
||
| 156 | */ |
||
| 157 | public function compileContentItem (&$contentItem) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Add a new ContentItem to the respective parent PageView of the ContentItem |
||
| 181 | * |
||
| 182 | * @param ContentItem $contentItem |
||
| 183 | */ |
||
| 184 | public function updatePageView ($contentItem) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Update an existing Twig variable that's injected globally |
||
| 200 | * |
||
| 201 | * @param string $variable |
||
| 202 | * @param string $value |
||
| 203 | */ |
||
| 204 | public function updateTwigVariable ($variable, $value) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * {@inheritdoc} |
||
| 211 | */ |
||
| 212 | public function refreshItem($filePath) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * {@inheritdoc} |
||
| 219 | */ |
||
| 220 | 1 | protected function handleTrackableItem($filePath, $options = array()) |
|
| 247 | |||
| 248 | /** |
||
| 249 | * Compile a given PageView |
||
| 250 | * |
||
| 251 | * @param string $filePath The file path to the PageView to compile |
||
| 252 | * @param bool $refresh When set to true, the PageView will reread its contents |
||
| 253 | * |
||
| 254 | * @throws \Exception |
||
| 255 | */ |
||
| 256 | 1 | private function compileFromFilePath ($filePath, $refresh = false) |
|
| 283 | |||
| 284 | /** |
||
| 285 | * @param DynamicPageView|PageView|RepeaterPageView $pageView |
||
| 286 | * @param bool $refresh |
||
| 287 | */ |
||
| 288 | 1 | private function compilePageView ($pageView, $refresh = false) |
|
| 309 | |||
| 310 | /** |
||
| 311 | * @param RepeaterPageView $pageView |
||
| 312 | */ |
||
| 313 | 1 | private function compileRepeaterPageView (&$pageView) |
|
| 337 | |||
| 338 | /** |
||
| 339 | * @param PageView $pageView |
||
| 340 | */ |
||
| 341 | private function compileDynamicPageView (&$pageView) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @param PageView $pageView |
||
| 362 | */ |
||
| 363 | private function compileStaticPageView (&$pageView) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Add a static PageView to the menu array. Dynamic PageViews are not added to the menu |
||
| 378 | * |
||
| 379 | * @param PageView $pageView |
||
| 380 | */ |
||
| 381 | private function addToSiteMenu (&$pageView) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @param PageView $pageView |
||
| 428 | * |
||
| 429 | * @return Twig_Template |
||
| 430 | * @throws Twig_Error_Syntax |
||
| 431 | */ |
||
| 432 | 1 | private function createTemplate ($pageView) |
|
| 445 | } |