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 |
||
23 | class Storage |
||
24 | { |
||
25 | /** |
||
26 | * @var SitemapStorage |
||
27 | */ |
||
28 | protected $sitemap; |
||
29 | /** |
||
30 | * @var ImagesStorage |
||
31 | */ |
||
32 | protected $images; |
||
33 | /** |
||
34 | * @var ImageSetStorage |
||
35 | */ |
||
36 | protected $imageSet; |
||
37 | /** |
||
38 | * @var FilesStorage |
||
39 | */ |
||
40 | protected $files; |
||
41 | /** |
||
42 | * @var UsersStorage |
||
43 | */ |
||
44 | protected $users; |
||
45 | /** |
||
46 | * @var DocumentTypesStorage |
||
47 | */ |
||
48 | protected $documentTypes; |
||
49 | /** |
||
50 | * @var BricksStorage |
||
51 | */ |
||
52 | protected $bricks; |
||
53 | /** |
||
54 | * @var ApplicationComponentsStorage |
||
55 | */ |
||
56 | protected $applicationComponents; |
||
57 | |||
58 | /** |
||
59 | * @var ValuelistsStorage |
||
60 | */ |
||
61 | protected $valuelists; |
||
62 | /** |
||
63 | * @var DocumentStorage |
||
64 | */ |
||
65 | protected $documents; |
||
66 | /** |
||
67 | * @var RedirectsStorage |
||
68 | */ |
||
69 | protected $redirects; |
||
70 | |||
71 | /** |
||
72 | * @var ActivityLogStorage |
||
73 | */ |
||
74 | protected $activityLog; |
||
75 | /** |
||
76 | * @var String |
||
77 | */ |
||
78 | protected $imagesDir; |
||
79 | /** |
||
80 | * @var String |
||
81 | */ |
||
82 | protected $filesDir; |
||
83 | |||
84 | /** |
||
85 | * @var String |
||
86 | */ |
||
87 | private $storageDir; |
||
88 | /** |
||
89 | * @var Repository |
||
90 | */ |
||
91 | private $repository; |
||
92 | |||
93 | /** |
||
94 | * JsonStorage constructor. |
||
95 | * |
||
96 | * @param string $storageDir |
||
97 | * @param $imagesDir |
||
98 | * @param $filesDir |
||
99 | */ |
||
100 | public function __construct($storageDir, $imagesDir, $filesDir) |
||
107 | |||
108 | /** |
||
109 | * Retrieve the data from the storagepath |
||
110 | * so it can be interacted with |
||
111 | * |
||
112 | * @throws \Exception |
||
113 | */ |
||
114 | private function config() |
||
124 | |||
125 | /** |
||
126 | * @return \CloudControl\Cms\storage\storage\UsersStorage |
||
127 | */ |
||
128 | public function getUsers() |
||
135 | |||
136 | /** |
||
137 | * Get documents |
||
138 | * |
||
139 | * @return DocumentStorage |
||
140 | */ |
||
141 | public function getDocuments() |
||
148 | |||
149 | /** |
||
150 | * @return SitemapStorage |
||
151 | */ |
||
152 | public function getSitemap() |
||
159 | |||
160 | /** |
||
161 | * Get all images |
||
162 | * |
||
163 | * @return ImagesStorage |
||
164 | */ |
||
165 | public function getImages() |
||
173 | |||
174 | /** |
||
175 | * Get all files |
||
176 | * |
||
177 | * @return FilesStorage |
||
178 | */ |
||
179 | public function getFiles() |
||
186 | |||
187 | /** |
||
188 | * @return string |
||
189 | */ |
||
190 | public function getStorageDir() |
||
194 | |||
195 | /** |
||
196 | * @return \PDO |
||
197 | */ |
||
198 | public function getContentDbHandle() |
||
202 | |||
203 | /** |
||
204 | * @return DocumentTypesStorage |
||
205 | */ |
||
206 | public function getDocumentTypes() |
||
213 | |||
214 | /** |
||
215 | * @return BricksStorage |
||
216 | */ |
||
217 | View Code Duplication | public function getBricks() |
|
224 | |||
225 | /** |
||
226 | * Get the image set |
||
227 | * |
||
228 | * @return ImageSetStorage |
||
229 | */ |
||
230 | View Code Duplication | public function getImageSet() |
|
237 | |||
238 | /** |
||
239 | * @return ApplicationComponentsStorage |
||
240 | */ |
||
241 | public function getApplicationComponents() |
||
248 | |||
249 | /** |
||
250 | * @return \CloudControl\Cms\storage\Repository |
||
251 | */ |
||
252 | public function getRepository() |
||
256 | |||
257 | /** |
||
258 | * @return \CloudControl\Cms\storage\storage\ValuelistsStorage |
||
259 | */ |
||
260 | public function getValuelists() |
||
267 | |||
268 | /** |
||
269 | * @return \CloudControl\Cms\storage\storage\RedirectsStorage |
||
270 | */ |
||
271 | public function getRedirects() |
||
278 | |||
279 | /** |
||
280 | * @return ActivityLogStorage |
||
281 | */ |
||
282 | public function getActivityLog() |
||
289 | |||
290 | |||
291 | } |
||
292 | } |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.