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 |
||
6 | class LocalRepository extends Repository |
||
7 | { |
||
8 | /** |
||
9 | * Get all modules. |
||
10 | * |
||
11 | * @return Collection |
||
12 | */ |
||
13 | public function all() |
||
25 | |||
26 | /** |
||
27 | * Get all module slugs. |
||
28 | * |
||
29 | * @return Collection |
||
30 | */ |
||
31 | public function slugs() |
||
41 | |||
42 | /** |
||
43 | * Get modules based on where clause. |
||
44 | * |
||
45 | * @param string $key |
||
46 | * @param mixed $value |
||
47 | * @return Collection |
||
48 | */ |
||
49 | public function where($key, $value) |
||
55 | |||
56 | /** |
||
57 | * Sort modules by given key in ascending order. |
||
58 | * |
||
59 | * @param string $key |
||
60 | * @return Collection |
||
61 | */ |
||
62 | public function sortBy($key) |
||
68 | |||
69 | /** |
||
70 | * Sort modules by given key in ascending order. |
||
71 | * |
||
72 | * @param string $key |
||
73 | * @return Collection |
||
74 | */ |
||
75 | public function sortByDesc($key) |
||
81 | |||
82 | /** |
||
83 | * Determines if the given module exists. |
||
84 | * |
||
85 | * @param string $slug |
||
86 | * @return bool |
||
87 | */ |
||
88 | public function exists($slug) |
||
92 | |||
93 | /** |
||
94 | * Returns count of all modules. |
||
95 | * |
||
96 | * @return int |
||
97 | */ |
||
98 | public function count() |
||
102 | |||
103 | /** |
||
104 | * Get a module's properties. |
||
105 | * |
||
106 | * @param string $slug |
||
107 | * @return Collection|null |
||
108 | */ |
||
109 | public function getProperties($slug) |
||
130 | |||
131 | /** |
||
132 | * Get a module property value. |
||
133 | * |
||
134 | * @param string $property |
||
135 | * @param mixed $default |
||
136 | * @return mixed |
||
137 | */ |
||
138 | public function getProperty($property, $default = null) |
||
144 | |||
145 | /** |
||
146 | * Set the given module property value. |
||
147 | * |
||
148 | * @param string $property |
||
149 | * @param mixed $value |
||
150 | * @return bool |
||
151 | */ |
||
152 | public function setProperty($property, $value) |
||
168 | |||
169 | /** |
||
170 | * Get all enabled modules. |
||
171 | * |
||
172 | * @return Collection |
||
173 | */ |
||
174 | View Code Duplication | public function enabled() |
|
186 | |||
187 | /** |
||
188 | * Get all disabled modules. |
||
189 | * |
||
190 | * @return Collection |
||
191 | */ |
||
192 | View Code Duplication | public function disabled() |
|
204 | |||
205 | /** |
||
206 | * Check if specified module is enabled. |
||
207 | * |
||
208 | * @param string $slug |
||
209 | * @return bool |
||
210 | */ |
||
211 | public function isEnabled($slug) |
||
217 | |||
218 | /** |
||
219 | * Check if specified module is disabled. |
||
220 | * |
||
221 | * @param string $slug |
||
222 | * @return bool |
||
223 | */ |
||
224 | public function isDisabled($slug) |
||
230 | |||
231 | /** |
||
232 | * Enables the specified module. |
||
233 | * |
||
234 | * @param string $slug |
||
235 | * @return bool |
||
236 | */ |
||
237 | public function enable($slug) |
||
241 | |||
242 | /** |
||
243 | * Disables the specified module. |
||
244 | * |
||
245 | * @param string $slug |
||
246 | * @return bool |
||
247 | */ |
||
248 | public function disable($slug) |
||
252 | |||
253 | /** |
||
254 | * Refresh the cache with any newly found modules. |
||
255 | * |
||
256 | * @return bool |
||
257 | */ |
||
258 | public function cache() |
||
276 | |||
277 | /** |
||
278 | * Get the contents of the cache file. |
||
279 | * |
||
280 | * The cache file lists all module slugs and their |
||
281 | * enabled or disabled status. This can be used to |
||
282 | * filter out modules depending on their status. |
||
283 | * |
||
284 | * @return Collection |
||
285 | */ |
||
286 | public function getCache() |
||
307 | |||
308 | /** |
||
309 | * Set the given cache key value. |
||
310 | * |
||
311 | * @param string $key |
||
312 | * @param mixed $value |
||
313 | * @return int |
||
314 | */ |
||
315 | public function setCache($key, $value) |
||
326 | } |
||
327 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.