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 |
||
| 25 | class PageManager extends TrackingManager |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * The relative (to the stakx project) file path to the redirect template |
||
| 29 | * |
||
| 30 | * @var string|bool |
||
| 31 | */ |
||
| 32 | private $redirectTemplate; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var ContentItem[][] |
||
| 36 | */ |
||
| 37 | private $collections; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var Folder |
||
| 41 | */ |
||
| 42 | private $targetDir; |
||
| 43 | |||
| 44 | private $siteMenu; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var \Twig_Environment |
||
| 48 | */ |
||
| 49 | private $twig; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * PageManager constructor |
||
| 53 | */ |
||
| 54 | 1 | public function __construct() |
|
| 60 | |||
| 61 | public function setCollections (&$collections) |
||
| 67 | |||
| 68 | 1 | public function setRedirectTemplate ($filePath) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * @param Folder $folder The relative target directory as specified from the configuration file |
||
| 75 | */ |
||
| 76 | 1 | public function setTargetFolder (&$folder) |
|
| 80 | |||
| 81 | 1 | public function configureTwig ($configuration, $options) |
|
| 88 | |||
| 89 | /** |
||
| 90 | * An array representing the website's menu structure with children and grandchildren made from static PageViews |
||
| 91 | * |
||
| 92 | * @return array |
||
| 93 | */ |
||
| 94 | public function getSiteMenu () |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Go through all of the PageView directories and create a respective PageView for each and classify them as a |
||
| 101 | * dynamic or static PageView. |
||
| 102 | * |
||
| 103 | * @param $pageViewFolders |
||
| 104 | */ |
||
| 105 | 1 | public function parsePageViews ($pageViewFolders) |
|
| 131 | |||
| 132 | /** |
||
| 133 | * Compile dynamic and static PageViews |
||
| 134 | */ |
||
| 135 | 1 | public function compileAll () |
|
| 142 | |||
| 143 | public function compileSome ($filter = array()) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param ContentItem $contentItem |
||
| 157 | */ |
||
| 158 | public function compileContentItem (&$contentItem) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Add a new ContentItem to the respective parent PageView of the ContentItem |
||
| 182 | * |
||
| 183 | * @param ContentItem $contentItem |
||
| 184 | */ |
||
| 185 | public function updatePageView ($contentItem) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Update an existing Twig variable that's injected globally |
||
| 201 | * |
||
| 202 | * @param string $variable |
||
| 203 | * @param string $value |
||
| 204 | */ |
||
| 205 | public function updateTwigVariable ($variable, $value) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * {@inheritdoc} |
||
| 212 | */ |
||
| 213 | public function refreshItem($filePath) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * {@inheritdoc} |
||
| 220 | */ |
||
| 221 | 1 | protected function handleTrackableItem($filePath, $options = array()) |
|
| 248 | |||
| 249 | /** |
||
| 250 | * Compile a given PageView |
||
| 251 | * |
||
| 252 | * @param string $filePath The file path to the PageView to compile |
||
| 253 | * @param bool $refresh When set to true, the PageView will reread its contents |
||
| 254 | * |
||
| 255 | * @throws \Exception |
||
| 256 | */ |
||
| 257 | 1 | private function compileFromFilePath ($filePath, $refresh = false) |
|
| 269 | |||
| 270 | /** |
||
| 271 | * @param DynamicPageView|PageView|RepeaterPageView $pageView |
||
| 272 | * @param bool $refresh |
||
| 273 | */ |
||
| 274 | 1 | private function compilePageView ($pageView, $refresh = false) |
|
| 299 | |||
| 300 | /** |
||
| 301 | * @param RepeaterPageView $pageView |
||
| 302 | */ |
||
| 303 | 1 | private function compileRepeaterPageView (&$pageView) |
|
| 327 | |||
| 328 | /** |
||
| 329 | * @param PageView $pageView |
||
| 330 | */ |
||
| 331 | private function compileDynamicPageView (&$pageView) |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @param PageView $pageView |
||
| 352 | */ |
||
| 353 | private function compileStaticPageView (&$pageView) |
||
| 365 | |||
| 366 | /** |
||
| 367 | * @param DynamicPageView|PageView $pageView |
||
| 368 | */ |
||
| 369 | private function compileNormalRedirects (&$pageView) |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @param RepeaterPageView $pageView |
||
| 385 | */ |
||
| 386 | 1 | private function compileExpandedRedirects (&$pageView) |
|
| 408 | |||
| 409 | /** |
||
| 410 | * Add a static PageView to the menu array. Dynamic PageViews are not added to the menu |
||
| 411 | * |
||
| 412 | * @param PageView $pageView |
||
| 413 | */ |
||
| 414 | private function addToSiteMenu (&$pageView) |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @param PageView $pageView |
||
| 461 | * |
||
| 462 | * @return Twig_Template |
||
| 463 | * @throws Twig_Error_Syntax |
||
| 464 | */ |
||
| 465 | 1 | private function createTemplate ($pageView) |
|
| 478 | } |