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 |
||
21 | class Storage |
||
22 | { |
||
23 | /** |
||
24 | * @var SitemapStorage |
||
25 | */ |
||
26 | protected $sitemap; |
||
27 | /** |
||
28 | * @var ImagesStorage |
||
29 | */ |
||
30 | protected $images; |
||
31 | /** |
||
32 | * @var ImageSetStorage |
||
33 | */ |
||
34 | protected $imageSet; |
||
35 | /** |
||
36 | * @var FilesStorage |
||
37 | */ |
||
38 | protected $files; |
||
39 | /** |
||
40 | * @var UsersStorage |
||
41 | */ |
||
42 | protected $users; |
||
43 | /** |
||
44 | * @var DocumentTypesStorage |
||
45 | */ |
||
46 | protected $documentTypes; |
||
47 | /** |
||
48 | * @var BricksStorage |
||
49 | */ |
||
50 | protected $bricks; |
||
51 | /** |
||
52 | * @var ApplicationComponentsStorage |
||
53 | */ |
||
54 | protected $applicationComponents; |
||
55 | |||
56 | /** |
||
57 | * @var ValuelistsStorage |
||
58 | */ |
||
59 | protected $valuelists; |
||
60 | /** |
||
61 | * @var DocumentStorage |
||
62 | */ |
||
63 | protected $documents; |
||
64 | /** |
||
65 | * @var RedirectsStorage |
||
66 | */ |
||
67 | protected $redirects; |
||
68 | /** |
||
69 | * @var String |
||
70 | */ |
||
71 | protected $imagesDir; |
||
72 | /** |
||
73 | * @var String |
||
74 | */ |
||
75 | protected $filesDir; |
||
76 | |||
77 | /** |
||
78 | * @var String |
||
79 | */ |
||
80 | private $storageDir; |
||
81 | /** |
||
82 | * @var Repository |
||
83 | */ |
||
84 | private $repository; |
||
85 | |||
86 | /** |
||
87 | * JsonStorage constructor. |
||
88 | * |
||
89 | * @param string $storageDir |
||
90 | * @param $imagesDir |
||
91 | * @param $filesDir |
||
92 | */ |
||
93 | public function __construct($storageDir, $imagesDir, $filesDir) |
||
100 | |||
101 | /** |
||
102 | * Retrieve the data from the storagepath |
||
103 | * so it can be interacted with |
||
104 | * |
||
105 | * @throws \Exception |
||
106 | */ |
||
107 | private function config() |
||
123 | |||
124 | /** |
||
125 | * @return \CloudControl\Cms\storage\storage\UsersStorage |
||
126 | */ |
||
127 | public function getUsers() |
||
134 | |||
135 | /** |
||
136 | * Get documents |
||
137 | * |
||
138 | * @return DocumentStorage |
||
139 | */ |
||
140 | public function getDocuments() |
||
147 | |||
148 | /** |
||
149 | * Add new document in given path |
||
150 | * |
||
151 | * @param array $postValues |
||
152 | * |
||
153 | * @throws \Exception |
||
154 | */ |
||
155 | public function addDocumentFolder($postValues) |
||
166 | |||
167 | /** |
||
168 | * Delete a folder by its compound slug |
||
169 | * |
||
170 | * @param $slug |
||
171 | * |
||
172 | * @throws \Exception |
||
173 | */ |
||
174 | public function deleteDocumentFolderBySlug($slug) |
||
181 | |||
182 | public function publishDocumentBySlug($slug) |
||
187 | |||
188 | public function unpublishDocumentBySlug($slug) |
||
193 | |||
194 | /** |
||
195 | * Retrieve a folder by its compound slug |
||
196 | * |
||
197 | * @param $slug |
||
198 | * |
||
199 | * @return mixed |
||
200 | * @throws \Exception |
||
201 | */ |
||
202 | public function getDocumentFolderBySlug($slug) |
||
208 | |||
209 | /** |
||
210 | * Save changes to folder |
||
211 | * |
||
212 | * @param $postValues |
||
213 | * |
||
214 | * @throws \Exception |
||
215 | */ |
||
216 | public function saveDocumentFolder($postValues) |
||
220 | |||
221 | /** |
||
222 | * @return SitemapStorage |
||
223 | */ |
||
224 | public function getSitemap() |
||
231 | |||
232 | /** |
||
233 | * Get all images |
||
234 | * |
||
235 | * @return ImagesStorage |
||
236 | */ |
||
237 | public function getImages() |
||
245 | |||
246 | /** |
||
247 | * Get all files |
||
248 | * |
||
249 | * @return FilesStorage |
||
250 | */ |
||
251 | public function getFiles() |
||
258 | |||
259 | /** |
||
260 | * @return string |
||
261 | */ |
||
262 | public function getStorageDir() |
||
266 | |||
267 | /** |
||
268 | * @return \PDO |
||
269 | */ |
||
270 | public function getContentDbHandle() |
||
274 | |||
275 | /** |
||
276 | * @return DocumentTypesStorage |
||
277 | */ |
||
278 | public function getDocumentTypes() |
||
285 | |||
286 | /** |
||
287 | * @return BricksStorage |
||
288 | */ |
||
289 | View Code Duplication | public function getBricks() |
|
296 | |||
297 | /** |
||
298 | * Get the image set |
||
299 | * |
||
300 | * @return ImageSetStorage |
||
301 | */ |
||
302 | View Code Duplication | public function getImageSet() |
|
309 | |||
310 | /** |
||
311 | * @return ApplicationComponentsStorage |
||
312 | */ |
||
313 | public function getApplicationComponents() |
||
320 | |||
321 | /** |
||
322 | * @return \CloudControl\Cms\storage\Repository |
||
323 | */ |
||
324 | public function getRepository() |
||
328 | |||
329 | /** |
||
330 | * @return \CloudControl\Cms\storage\storage\ValuelistsStorage |
||
331 | */ |
||
332 | public function getValuelists() |
||
339 | |||
340 | /** |
||
341 | * @return \CloudControl\Cms\storage\storage\RedirectsStorage |
||
342 | */ |
||
343 | public function getRedirects() |
||
350 | |||
351 | } |
||
352 | } |