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 namespace Anomaly\Streams\Platform\Addon; |
||
15 | class AddonManager |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * The addon paths. |
||
20 | * |
||
21 | * @var AddonPaths |
||
22 | */ |
||
23 | protected $paths; |
||
24 | |||
25 | /** |
||
26 | * The addon collection. |
||
27 | * |
||
28 | * @var AddonCollection |
||
29 | */ |
||
30 | protected $addons; |
||
31 | |||
32 | /** |
||
33 | * The addon loader. |
||
34 | * |
||
35 | * @var AddonLoader |
||
36 | */ |
||
37 | protected $loader; |
||
38 | |||
39 | /** |
||
40 | * The addon integrator. |
||
41 | * |
||
42 | * @var AddonIntegrator |
||
43 | */ |
||
44 | protected $integrator; |
||
45 | |||
46 | /** |
||
47 | * The modules model. |
||
48 | * |
||
49 | * @var ModuleModel |
||
50 | */ |
||
51 | protected $modules; |
||
52 | |||
53 | /** |
||
54 | * The event dispatcher. |
||
55 | * |
||
56 | * @var Dispatcher |
||
57 | */ |
||
58 | protected $dispatcher; |
||
59 | |||
60 | /** |
||
61 | * The extensions model. |
||
62 | * |
||
63 | * @var ExtensionModel |
||
64 | */ |
||
65 | protected $extensions; |
||
66 | |||
67 | /** |
||
68 | * Create a new AddonManager instance. |
||
69 | * |
||
70 | * @param AddonPaths $paths |
||
71 | * @param AddonLoader $loader |
||
72 | * @param ModuleModel $modules |
||
73 | * @param Dispatcher $dispatcher |
||
74 | * @param ExtensionModel $extensions |
||
75 | * @param AddonIntegrator $integrator |
||
76 | * @param AddonCollection $addons |
||
77 | */ |
||
78 | public function __construct( |
||
95 | |||
96 | /** |
||
97 | * Register all addons. |
||
98 | */ |
||
99 | public function register() |
||
146 | |||
147 | /** |
||
148 | * Get namespaces for enabled addons. |
||
149 | * |
||
150 | * @return array |
||
151 | */ |
||
152 | View Code Duplication | protected function getEnabledAddonNamespaces() |
|
176 | |||
177 | /** |
||
178 | * Get namespaces for installed addons. |
||
179 | * |
||
180 | * @return array |
||
181 | */ |
||
182 | View Code Duplication | protected function getInstalledAddonNamespaces() |
|
206 | |||
207 | /** |
||
208 | * Get the addon namespace. |
||
209 | * |
||
210 | * @param $path |
||
211 | * @return string |
||
212 | */ |
||
213 | protected function getAddonNamespace($path) |
||
221 | } |
||
222 |
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.