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 Classes_Handler { |
||
16 | |||
17 | /** |
||
18 | * The Plugins_Handler object. |
||
19 | * |
||
20 | * @var Plugins_Handler |
||
21 | */ |
||
22 | private $plugins_handler = null; |
||
23 | |||
24 | /** |
||
25 | * The Version_Selector object. |
||
26 | * |
||
27 | * @var Version_Selector |
||
28 | */ |
||
29 | private $version_selector = null; |
||
30 | |||
31 | /** |
||
32 | * The constructor. |
||
33 | * |
||
34 | * @param Plugins_Handler $plugins_handler The Plugins_Handler object. |
||
35 | * @param Version_Selector $version_selector The Version_Selector object. |
||
36 | */ |
||
37 | public function __construct( $plugins_handler, $version_selector ) { |
||
41 | |||
42 | /** |
||
43 | * Adds the version of a package to the $jetpack_packages_classmap global |
||
44 | * array so that the autoloader is able to find it. |
||
45 | * |
||
46 | * @param string $class_name Name of the class that you want to autoload. |
||
47 | * @param string $version Version of the class. |
||
48 | * @param string $path Absolute path to the class so that we can load it. |
||
49 | */ |
||
50 | View Code Duplication | public function enqueue_package_class( $class_name, $version, $path ) { |
|
66 | |||
67 | /** |
||
68 | * Creates the path to the plugin's classmap file. The classmap filename is the filename |
||
69 | * generated by Jetpack Autoloader version >= 2.0. |
||
70 | * |
||
71 | * @param String $plugin_path The plugin path. |
||
72 | * |
||
73 | * @return String the classmap path. |
||
74 | */ |
||
75 | public function create_classmap_path( $plugin_path ) { |
||
78 | |||
79 | /** |
||
80 | * Initializes the classmap. |
||
81 | */ |
||
82 | View Code Duplication | public function set_class_paths() { |
|
98 | } |
||
99 |