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 |
||
26 | class PageManager extends TrackingManager |
||
27 | { |
||
28 | /** |
||
29 | * The relative (to the stakx project) file path to the redirect template |
||
30 | * |
||
31 | * @var string|bool |
||
32 | */ |
||
33 | private $redirectTemplate; |
||
34 | |||
35 | /** |
||
36 | * @var PageView[] |
||
37 | */ |
||
38 | private $twigExtendsDeps; |
||
39 | |||
40 | /** |
||
41 | * @var ContentItem[][] |
||
42 | */ |
||
43 | private $collections; |
||
44 | |||
45 | /** |
||
46 | * @var Folder |
||
47 | */ |
||
48 | private $targetDir; |
||
49 | |||
50 | /** |
||
51 | * @var PageView[] |
||
52 | */ |
||
53 | private $flatPages; |
||
54 | |||
55 | private $siteMenu; |
||
56 | |||
57 | private $twigOpts; |
||
58 | |||
59 | /** |
||
60 | * @var \Twig_Environment |
||
61 | */ |
||
62 | private $twig; |
||
63 | |||
64 | /** |
||
65 | * PageManager constructor |
||
66 | 1 | */ |
|
67 | 1 | public function __construct() |
|
73 | 1 | ||
74 | public function setCollections (&$collections) |
||
80 | |||
81 | public function setRedirectTemplate ($filePath) |
||
85 | |||
86 | /** |
||
87 | * @param Folder $folder The relative target directory as specified from the configuration file |
||
88 | 1 | */ |
|
89 | public function setTargetFolder (&$folder) |
||
93 | 1 | ||
94 | public function configureTwig ($configuration, $options) |
||
101 | 1 | ||
102 | public function createTwigManager () |
||
112 | |||
113 | public function getFlatPages () |
||
117 | |||
118 | /** |
||
119 | * An array representing the website's menu structure with children and grandchildren made from static PageViews |
||
120 | * |
||
121 | * @return JailObject[] |
||
122 | */ |
||
123 | public function getSiteMenu () |
||
144 | |||
145 | /** |
||
146 | * Go through all of the PageView directories and create a respective PageView for each and classify them as a |
||
147 | * dynamic or static PageView. |
||
148 | * |
||
149 | * @param $pageViewFolders |
||
150 | 1 | */ |
|
151 | public function parsePageViews ($pageViewFolders) |
||
177 | |||
178 | /** |
||
179 | * Compile dynamic and static PageViews |
||
180 | 1 | */ |
|
181 | public function compileAll () |
||
188 | |||
189 | public function compileSome ($filter = array()) |
||
200 | |||
201 | /** |
||
202 | * @param ContentItem $contentItem |
||
203 | */ |
||
204 | public function compileContentItem (&$contentItem) |
||
225 | |||
226 | /** |
||
227 | * Add a new ContentItem to the respective parent PageView of the ContentItem |
||
228 | * |
||
229 | * @param ContentItem $contentItem |
||
230 | */ |
||
231 | public function updatePageView ($contentItem) |
||
244 | |||
245 | /** |
||
246 | * Update an existing Twig variable that's injected globally |
||
247 | * |
||
248 | * @param string $variable |
||
249 | * @param string $value |
||
250 | */ |
||
251 | public function updateTwigVariable ($variable, $value) |
||
255 | |||
256 | /** |
||
257 | * {@inheritdoc} |
||
258 | 1 | */ |
|
259 | public function isTracked($filePath) |
||
263 | |||
264 | /** |
||
265 | * {@inheritdoc} |
||
266 | */ |
||
267 | public function refreshItem($filePath) |
||
283 | |||
284 | /** |
||
285 | * {@inheritdoc} |
||
286 | 1 | */ |
|
287 | protected function handleTrackableItem($filePath, $options = array()) |
||
315 | 1 | ||
316 | 1 | /** |
|
317 | * Compile a given PageView |
||
318 | * |
||
319 | * @param string $filePath The file path to the PageView to compile |
||
320 | * @param bool $refresh When set to true, the PageView will reread its contents |
||
321 | * |
||
322 | * @throws \Exception |
||
323 | */ |
||
324 | private function compileFromFilePath ($filePath, $refresh = false) |
||
336 | 1 | ||
337 | 1 | /** |
|
338 | * @param DynamicPageView|PageView|RepeaterPageView $pageView |
||
339 | * @param bool $refresh |
||
340 | */ |
||
341 | private function compilePageView ($pageView, $refresh = false) |
||
366 | 1 | ||
367 | 1 | /** |
|
368 | * @param RepeaterPageView $pageView |
||
369 | */ |
||
370 | private function compileRepeaterPageView (&$pageView) |
||
391 | 1 | ||
392 | 1 | /** |
|
393 | * @param PageView $pageView |
||
394 | */ |
||
395 | private function compileDynamicPageView (&$pageView) |
||
413 | |||
414 | /** |
||
415 | * @param PageView $pageView |
||
416 | */ |
||
417 | private function compileStaticPageView (&$pageView) |
||
429 | 1 | ||
430 | 1 | /** |
|
431 | * @param DynamicPageView|PageView $pageView |
||
432 | */ |
||
433 | private function compileNormalRedirects (&$pageView) |
||
446 | 1 | ||
447 | 1 | /** |
|
448 | * @param RepeaterPageView $pageView |
||
449 | */ |
||
450 | private function compileExpandedRedirects (&$pageView) |
||
473 | 1 | ||
474 | 1 | /** |
|
475 | * Add a static PageView to the menu array. Dynamic PageViews are not added to the menu |
||
476 | * |
||
477 | * @param PageView $pageView |
||
478 | */ |
||
479 | private function addToSiteMenu (&$pageView) |
||
524 | |||
525 | /** |
||
526 | * @param PageView $pageView |
||
527 | * |
||
528 | * @return Twig_Template |
||
529 | 1 | * @throws Twig_Error_Syntax |
|
530 | */ |
||
531 | private function createTemplate (&$pageView) |
||
549 | |||
550 | /** |
||
551 | * Find the parent Twig templates of the given template and keep a list of it |
||
552 | * |
||
553 | * @param Twig_Template $template The template created from the PageView's content |
||
554 | 1 | * @param PageView $pageView The PageView that has this content. Used to keep a reference of PageViews |
|
555 | */ |
||
556 | 1 | private function trackParentTwigTemplate ($template, &$pageView) |
|
571 | } |