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 |
||
15 | class Manifest_Handler { |
||
16 | |||
17 | /** |
||
18 | * An array of the active plugin paths we want to search. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | private $active_plugin_paths; |
||
23 | |||
24 | /** |
||
25 | * The Version_Selector object. |
||
26 | * |
||
27 | * @var Version_Selector |
||
28 | */ |
||
29 | private $version_selector; |
||
30 | |||
31 | /** |
||
32 | * The constructor. |
||
33 | * |
||
34 | * @param array $active_plugin_paths An array of the active plugin paths we want to search. |
||
35 | * @param Version_Selector $version_selector The Version_Selector object. |
||
36 | */ |
||
37 | public function __construct( $active_plugin_paths, $version_selector ) { |
||
41 | |||
42 | /** |
||
43 | * Registers all of the paths in a given manifest. |
||
44 | * |
||
45 | * @param string $manifest_path The path that we're loading the manifest from in each plugin. |
||
46 | * @param array $path_map The path map to add the contents of the manifests to. |
||
47 | * |
||
48 | * @return array $path_map The path map we've built using the manifests in each plugin. |
||
49 | */ |
||
50 | View Code Duplication | public function register_plugin_manifests( $manifest_path, &$path_map ) { |
|
64 | |||
65 | /** |
||
66 | * Registers a plugin's manifest file with the path map. |
||
67 | * |
||
68 | * @param string $manifest_path The absolute path to the manifest that we're loading. |
||
69 | * @param array $path_map The path map to add the contents of the manifest to. |
||
70 | */ |
||
71 | View Code Duplication | protected function register_manifest( $manifest_path, &$path_map ) { |
|
85 | |||
86 | /** |
||
87 | * Registers an entry from the manifest in the path map. |
||
88 | * |
||
89 | * @param string $key The identifier for the entry we're registering. |
||
90 | * @param array $data The data for the entry we're registering. |
||
91 | * @param array $path_map The path map to add the contents of the manifest to. |
||
92 | */ |
||
93 | View Code Duplication | protected function register_record( $key, $data, &$path_map ) { |
|
107 | } |
||
108 |