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 |
||
| 21 | class PageManager extends TrackingManager |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var ContentItem[][] |
||
| 25 | */ |
||
| 26 | private $collections; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var Folder |
||
| 30 | */ |
||
| 31 | private $targetDir; |
||
| 32 | |||
| 33 | private $siteMenu; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var \Twig_Environment |
||
| 37 | */ |
||
| 38 | private $twig; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * PageManager constructor |
||
| 42 | */ |
||
| 43 | public function __construct() |
||
| 47 | |||
| 48 | public function setCollections ($collections) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param Folder $folder The relative target directory as specified from the configuration file |
||
| 57 | */ |
||
| 58 | public function setTargetFolder (&$folder) |
||
| 62 | |||
| 63 | public function configureTwig ($configuration, $options) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * An array representing the website's menu structure with children and grandchildren made from static PageViews |
||
| 73 | * |
||
| 74 | * @return array |
||
| 75 | */ |
||
| 76 | public function getSiteMenu () |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Go through all of the PageView directories and create a respective PageView for each and classify them as a |
||
| 83 | * dynamic or static PageView. |
||
| 84 | * |
||
| 85 | * @param $pageViewFolders |
||
| 86 | */ |
||
| 87 | public function parsePageViews ($pageViewFolders) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Compile dynamic and static PageViews |
||
| 116 | */ |
||
| 117 | public function compileAll () |
||
| 124 | |||
| 125 | public function compileSome ($filter = array()) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @param ContentItem $contentItem |
||
| 139 | */ |
||
| 140 | public function compileContentItem (&$contentItem) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Update an existing Twig variable that's injected globally |
||
| 158 | * |
||
| 159 | * @param string $variable |
||
| 160 | * @param string $value |
||
| 161 | */ |
||
| 162 | public function updateTwigVariable ($variable, $value) |
||
| 166 | |||
| 167 | /** |
||
| 168 | * {@inheritdoc} |
||
| 169 | */ |
||
| 170 | public function refreshItem($filePath) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * {@inheritdoc} |
||
| 177 | */ |
||
| 178 | protected function handleTrackableItem($filePath, $options = array()) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Compile a given PageView |
||
| 209 | * |
||
| 210 | * @param string $filePath The file path to the PageView to compile |
||
| 211 | * @param bool $refresh When set to true, the PageView will reread its contents |
||
| 212 | * |
||
| 213 | * @throws \Exception |
||
| 214 | */ |
||
| 215 | private function compileFromFilePath ($filePath, $refresh = false) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @param PageView $pageView |
||
| 230 | * @param bool $refresh |
||
| 231 | */ |
||
| 232 | private function compilePageView ($pageView, $refresh = false) |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @param PageView $pageView |
||
| 251 | */ |
||
| 252 | private function compileDynamicPageView (&$pageView) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * @param PageView $pageView |
||
| 273 | */ |
||
| 274 | private function compileStaticPageView (&$pageView) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Add a static PageView to the menu array. Dynamic PageViews are not added to the menu |
||
| 289 | * |
||
| 290 | * @param array $frontMatter |
||
| 291 | */ |
||
| 292 | private function addToSiteMenu ($frontMatter) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @param PageView $pageView |
||
| 326 | * |
||
| 327 | * @return Twig_Template |
||
| 328 | * @throws Twig_Error_Syntax |
||
| 329 | */ |
||
| 330 | private function createTemplate ($pageView) |
||
| 343 | } |