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 PageView[] |
||
| 36 | */ |
||
| 37 | private $twigExtendsDeps; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var ContentItem[][] |
||
| 41 | */ |
||
| 42 | private $collections; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var Folder |
||
| 46 | */ |
||
| 47 | private $targetDir; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var PageView[] |
||
| 51 | */ |
||
| 52 | private $flatPages; |
||
| 53 | |||
| 54 | private $siteMenu; |
||
| 55 | |||
| 56 | private $twigOpts; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var \Twig_Environment |
||
| 60 | */ |
||
| 61 | private $twig; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * PageManager constructor |
||
| 65 | */ |
||
| 66 | 1 | public function __construct() |
|
| 72 | |||
| 73 | 1 | public function setCollections (&$collections) |
|
| 79 | |||
| 80 | public function setRedirectTemplate ($filePath) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param Folder $folder The relative target directory as specified from the configuration file |
||
| 87 | */ |
||
| 88 | 1 | public function setTargetFolder (&$folder) |
|
| 92 | |||
| 93 | 1 | public function configureTwig ($configuration, $options) |
|
| 100 | |||
| 101 | 1 | public function createTwigManager () |
|
| 111 | |||
| 112 | public function getFlatPages () |
||
| 116 | |||
| 117 | /** |
||
| 118 | * An array representing the website's menu structure with children and grandchildren made from static PageViews |
||
| 119 | * |
||
| 120 | * @return array |
||
| 121 | */ |
||
| 122 | public function getSiteMenu () |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Go through all of the PageView directories and create a respective PageView for each and classify them as a |
||
| 129 | * dynamic or static PageView. |
||
| 130 | * |
||
| 131 | * @param $pageViewFolders |
||
| 132 | */ |
||
| 133 | 1 | public function parsePageViews ($pageViewFolders) |
|
| 159 | |||
| 160 | /** |
||
| 161 | * Compile dynamic and static PageViews |
||
| 162 | */ |
||
| 163 | 1 | public function compileAll () |
|
| 170 | |||
| 171 | public function compileSome ($filter = array()) |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param ContentItem $contentItem |
||
| 185 | */ |
||
| 186 | public function compileContentItem (&$contentItem) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Add a new ContentItem to the respective parent PageView of the ContentItem |
||
| 210 | * |
||
| 211 | * @param ContentItem $contentItem |
||
| 212 | */ |
||
| 213 | public function updatePageView ($contentItem) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Update an existing Twig variable that's injected globally |
||
| 229 | * |
||
| 230 | * @param string $variable |
||
| 231 | * @param string $value |
||
| 232 | */ |
||
| 233 | public function updateTwigVariable ($variable, $value) |
||
| 237 | |||
| 238 | /** |
||
| 239 | * {@inheritdoc} |
||
| 240 | */ |
||
| 241 | 1 | public function isTracked($filePath) |
|
| 245 | |||
| 246 | /** |
||
| 247 | * {@inheritdoc} |
||
| 248 | */ |
||
| 249 | public function refreshItem($filePath) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * {@inheritdoc} |
||
| 268 | */ |
||
| 269 | 1 | protected function handleTrackableItem($filePath, $options = array()) |
|
| 300 | |||
| 301 | /** |
||
| 302 | * Compile a given PageView |
||
| 303 | * |
||
| 304 | * @param string $filePath The file path to the PageView to compile |
||
| 305 | * @param bool $refresh When set to true, the PageView will reread its contents |
||
| 306 | * |
||
| 307 | * @throws \Exception |
||
| 308 | */ |
||
| 309 | 1 | private function compileFromFilePath ($filePath, $refresh = false) |
|
| 321 | |||
| 322 | /** |
||
| 323 | * @param DynamicPageView|PageView|RepeaterPageView $pageView |
||
| 324 | * @param bool $refresh |
||
| 325 | */ |
||
| 326 | 1 | private function compilePageView ($pageView, $refresh = false) |
|
| 351 | |||
| 352 | /** |
||
| 353 | * @param RepeaterPageView $pageView |
||
| 354 | */ |
||
| 355 | 1 | private function compileRepeaterPageView (&$pageView) |
|
| 376 | |||
| 377 | /** |
||
| 378 | * @param PageView $pageView |
||
| 379 | */ |
||
| 380 | private function compileDynamicPageView (&$pageView) |
||
| 398 | |||
| 399 | /** |
||
| 400 | * @param PageView $pageView |
||
| 401 | */ |
||
| 402 | private function compileStaticPageView (&$pageView) |
||
| 414 | |||
| 415 | /** |
||
| 416 | * @param DynamicPageView|PageView $pageView |
||
| 417 | */ |
||
| 418 | private function compileNormalRedirects (&$pageView) |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @param RepeaterPageView $pageView |
||
| 434 | */ |
||
| 435 | 1 | private function compileExpandedRedirects (&$pageView) |
|
| 458 | |||
| 459 | /** |
||
| 460 | * Add a static PageView to the menu array. Dynamic PageViews are not added to the menu |
||
| 461 | * |
||
| 462 | * @param PageView $pageView |
||
| 463 | */ |
||
| 464 | 1 | private function addToSiteMenu (&$pageView) |
|
| 508 | |||
| 509 | /** |
||
| 510 | * @param PageView $pageView |
||
| 511 | * |
||
| 512 | * @return Twig_Template |
||
| 513 | * @throws Twig_Error_Syntax |
||
| 514 | */ |
||
| 515 | 1 | private function createTemplate (&$pageView) |
|
| 533 | |||
| 534 | /** |
||
| 535 | * Find the parent Twig templates of the given template and keep a list of it |
||
| 536 | * |
||
| 537 | * @param Twig_Template $template The template created from the PageView's content |
||
| 538 | * @param PageView $pageView The PageView that has this content. Used to keep a reference of PageViews |
||
| 539 | */ |
||
| 540 | 1 | private function trackParentTwigTemplate ($template, &$pageView) |
|
| 555 | } |