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 |
||
14 | class HMBKP_Services { |
||
15 | |||
16 | /** |
||
17 | * Store the current instance |
||
18 | * |
||
19 | * @access private |
||
20 | * @var object HMBKP_Services |
||
21 | * @static |
||
22 | */ |
||
23 | private static $instance; |
||
24 | |||
25 | /** |
||
26 | * The array of services |
||
27 | * |
||
28 | * Should be of the format array( __FILE__ => __CLASS__ ); |
||
29 | * |
||
30 | * @access private |
||
31 | * @var array |
||
32 | * @static |
||
33 | */ |
||
34 | private $services = array(); |
||
35 | |||
36 | /** |
||
37 | * The current schedule object |
||
38 | * |
||
39 | * @access private |
||
40 | * @var object HMBKP_Scheduled_Backup |
||
41 | */ |
||
42 | private $schedule; |
||
43 | |||
44 | /** |
||
45 | * Get the current instance |
||
46 | * |
||
47 | * @access public |
||
48 | * @static |
||
49 | */ |
||
50 | public static function instance() { |
||
58 | |||
59 | /** |
||
60 | * Register a new service |
||
61 | * |
||
62 | * @param $filepath |
||
63 | * @param $classname |
||
64 | * @return bool|WP_Error |
||
65 | */ |
||
66 | public static function register( $filepath, $classname ) { |
||
70 | |||
71 | /** |
||
72 | * Instantiate the individual service classes |
||
73 | * |
||
74 | * @param string $classname |
||
75 | * |
||
76 | * @return array An array of instantiated classes |
||
77 | */ |
||
78 | View Code Duplication | private static function instantiate( $classname ) { |
|
91 | |||
92 | } |
||
93 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.