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 |
||
17 | View Code Duplication | class Autoloader_Locator { |
|
|
|||
18 | |||
19 | /** |
||
20 | * The object for comparing autoloader versions. |
||
21 | * |
||
22 | * @var Version_Selector |
||
23 | */ |
||
24 | private $version_selector; |
||
25 | |||
26 | /** |
||
27 | * The constructor. |
||
28 | * |
||
29 | * @param Version_Selector $version_selector The version selector object. |
||
30 | */ |
||
31 | public function __construct( $version_selector ) { |
||
34 | |||
35 | /** |
||
36 | * Finds the path to the plugin with the latest autoloader. |
||
37 | * |
||
38 | * @param array $plugin_paths An array of plugin paths. |
||
39 | * @param string $latest_version The latest version reference. |
||
40 | * |
||
41 | * @return string|null |
||
42 | */ |
||
43 | public function find_latest_autoloader( $plugin_paths, &$latest_version ) { |
||
58 | |||
59 | /** |
||
60 | * Gets the path to the autoloader. |
||
61 | * |
||
62 | * @param string $plugin_path The path to the plugin. |
||
63 | * |
||
64 | * @return string |
||
65 | */ |
||
66 | public function get_autoloader_path( $plugin_path ) { |
||
69 | |||
70 | /** |
||
71 | * Gets the version for the autoloader. |
||
72 | * |
||
73 | * @param string $plugin_path The path to the plugin. |
||
74 | * |
||
75 | * @return string|null |
||
76 | */ |
||
77 | public function get_autoloader_version( $plugin_path ) { |
||
90 | } |
||
91 |
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.