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 | private $siteMenu; |
||
50 | |||
51 | private $twigOpts; |
||
52 | |||
53 | /** |
||
54 | * @var \Twig_Environment |
||
55 | */ |
||
56 | private $twig; |
||
57 | |||
58 | /** |
||
59 | * PageManager constructor |
||
60 | */ |
||
61 | 1 | public function __construct() |
|
67 | |||
68 | public function setCollections (&$collections) |
||
74 | |||
75 | public function setRedirectTemplate ($filePath) |
||
79 | |||
80 | /** |
||
81 | * @param Folder $folder The relative target directory as specified from the configuration file |
||
82 | */ |
||
83 | 1 | public function setTargetFolder (&$folder) |
|
87 | |||
88 | 1 | public function configureTwig ($configuration, $options) |
|
95 | |||
96 | 1 | public function createTwigManager () |
|
106 | |||
107 | /** |
||
108 | * An array representing the website's menu structure with children and grandchildren made from static PageViews |
||
109 | * |
||
110 | * @return array |
||
111 | */ |
||
112 | public function getSiteMenu () |
||
116 | |||
117 | /** |
||
118 | * Go through all of the PageView directories and create a respective PageView for each and classify them as a |
||
119 | * dynamic or static PageView. |
||
120 | * |
||
121 | * @param $pageViewFolders |
||
122 | */ |
||
123 | 1 | public function parsePageViews ($pageViewFolders) |
|
149 | |||
150 | /** |
||
151 | * Compile dynamic and static PageViews |
||
152 | */ |
||
153 | 1 | public function compileAll () |
|
160 | |||
161 | public function compileSome ($filter = array()) |
||
172 | |||
173 | /** |
||
174 | * @param ContentItem $contentItem |
||
175 | */ |
||
176 | public function compileContentItem (&$contentItem) |
||
197 | |||
198 | /** |
||
199 | * Add a new ContentItem to the respective parent PageView of the ContentItem |
||
200 | * |
||
201 | * @param ContentItem $contentItem |
||
202 | */ |
||
203 | public function updatePageView ($contentItem) |
||
216 | |||
217 | /** |
||
218 | * Update an existing Twig variable that's injected globally |
||
219 | * |
||
220 | * @param string $variable |
||
221 | * @param string $value |
||
222 | */ |
||
223 | public function updateTwigVariable ($variable, $value) |
||
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | 1 | public function isTracked($filePath) |
|
235 | |||
236 | /** |
||
237 | * {@inheritdoc} |
||
238 | */ |
||
239 | public function refreshItem($filePath) |
||
255 | |||
256 | /** |
||
257 | * {@inheritdoc} |
||
258 | */ |
||
259 | 1 | protected function handleTrackableItem($filePath, $options = array()) |
|
286 | |||
287 | /** |
||
288 | * Compile a given PageView |
||
289 | * |
||
290 | * @param string $filePath The file path to the PageView to compile |
||
291 | * @param bool $refresh When set to true, the PageView will reread its contents |
||
292 | * |
||
293 | * @throws \Exception |
||
294 | */ |
||
295 | 1 | private function compileFromFilePath ($filePath, $refresh = false) |
|
307 | |||
308 | /** |
||
309 | * @param DynamicPageView|PageView|RepeaterPageView $pageView |
||
310 | * @param bool $refresh |
||
311 | */ |
||
312 | 1 | private function compilePageView ($pageView, $refresh = false) |
|
337 | |||
338 | /** |
||
339 | * @param RepeaterPageView $pageView |
||
340 | */ |
||
341 | 1 | private function compileRepeaterPageView (&$pageView) |
|
362 | |||
363 | /** |
||
364 | * @param PageView $pageView |
||
365 | */ |
||
366 | private function compileDynamicPageView (&$pageView) |
||
384 | |||
385 | /** |
||
386 | * @param PageView $pageView |
||
387 | */ |
||
388 | private function compileStaticPageView (&$pageView) |
||
400 | |||
401 | /** |
||
402 | * @param DynamicPageView|PageView $pageView |
||
403 | */ |
||
404 | private function compileNormalRedirects (&$pageView) |
||
417 | |||
418 | /** |
||
419 | * @param RepeaterPageView $pageView |
||
420 | */ |
||
421 | 1 | private function compileExpandedRedirects (&$pageView) |
|
444 | |||
445 | /** |
||
446 | * Add a static PageView to the menu array. Dynamic PageViews are not added to the menu |
||
447 | * |
||
448 | * @param PageView $pageView |
||
449 | */ |
||
450 | private function addToSiteMenu (&$pageView) |
||
494 | |||
495 | /** |
||
496 | * @param PageView $pageView |
||
497 | * |
||
498 | * @return Twig_Template |
||
499 | * @throws Twig_Error_Syntax |
||
500 | */ |
||
501 | 1 | private function createTemplate (&$pageView) |
|
519 | |||
520 | /** |
||
521 | * Find the parent Twig templates of the given template and keep a list of it |
||
522 | * |
||
523 | * @param Twig_Template $template The template created from the PageView's content |
||
524 | * @param PageView $pageView The PageView that has this content. Used to keep a reference of PageViews |
||
525 | */ |
||
526 | 1 | private function trackParentTwigTemplate ($template, &$pageView) |
|
541 | } |