Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
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 PageView[] |
||
46 | */ |
||
47 | private $flatPages; |
||
48 | |||
49 | /** |
||
50 | * PageManager constructor |
||
51 | */ |
||
52 | public function __construct() |
||
61 | |||
62 | /** |
||
63 | * Give this manager the collections we'll be using for dynamic PageViews |
||
64 | * |
||
65 | * @param ContentItem[][] $collections |
||
66 | */ |
||
67 | public function setCollections (&$collections) |
||
71 | |||
72 | public function getStaticPages () |
||
76 | |||
77 | View Code Duplication | public function getJailedStaticPages () |
|
94 | |||
95 | 3 | /** |
|
96 | * Go through all of the PageView directories and create a respective PageView for each and classify them as a |
||
97 | 3 | * dynamic or static PageView. |
|
98 | 3 | * |
|
99 | * @param $pageViewFolders |
||
100 | */ |
||
101 | public function parsePageViews ($pageViewFolders) |
||
125 | 3 | ||
126 | 3 | /** |
|
127 | * Add a new ContentItem to the respective parent PageView of the ContentItem |
||
128 | 1 | * |
|
129 | * @param ContentItem $contentItem |
||
130 | 1 | */ |
|
131 | public function updatePageView ($contentItem) |
||
144 | |||
145 | 1 | /** |
|
146 | 1 | * {@inheritdoc} |
|
147 | */ |
||
148 | public function isTracked($filePath) |
||
152 | |||
153 | 1 | /** |
|
154 | * @return PageView[] |
||
155 | */ |
||
156 | public function getPageViews () |
||
160 | |||
161 | /** |
||
162 | 3 | * {@inheritdoc} |
|
163 | */ |
||
164 | 3 | protected function handleTrackableItem($filePath, $options = array()) |
|
188 | |||
189 | /** |
||
190 | 3 | * @param DynamicPageView $pageView |
|
191 | */ |
||
192 | 3 | private function handleTrackableDynamicPageView ($pageView) |
|
208 | |||
209 | /** |
||
210 | * @param PageView $pageView |
||
211 | */ |
||
212 | private function handleTrackableStaticPageView ($pageView) |
||
218 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.