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 |
||
9 | class Services { |
||
10 | |||
11 | /** |
||
12 | * Store the current instance |
||
13 | * |
||
14 | * @access private |
||
15 | * @var object Services |
||
16 | * @static |
||
17 | */ |
||
18 | private static $instance; |
||
19 | |||
20 | /** |
||
21 | * The array of services |
||
22 | * |
||
23 | * Should be of the format array( __FILE__ => __CLASS__ ); |
||
24 | * |
||
25 | * @access private |
||
26 | * @var array |
||
27 | * @static |
||
28 | */ |
||
29 | private $services = array(); |
||
|
|||
30 | |||
31 | /** |
||
32 | * The current schedule object |
||
33 | * |
||
34 | * @access private |
||
35 | * @var object Scheduled_Backup |
||
36 | */ |
||
37 | private $schedule; |
||
38 | |||
39 | /** |
||
40 | * Get the current instance |
||
41 | * |
||
42 | * @static |
||
43 | */ |
||
44 | public static function instance() { |
||
53 | |||
54 | /** |
||
55 | * Get the array of registered services |
||
56 | * |
||
57 | * @param Scheduled_Backup $schedule |
||
58 | * @return Service[] |
||
59 | */ |
||
60 | public static function get_services( Scheduled_Backup $schedule = null ) { |
||
71 | |||
72 | public function get_available_services() { |
||
75 | |||
76 | /** |
||
77 | * Register a new service |
||
78 | * |
||
79 | * @param $filepath |
||
80 | * @param $classname |
||
81 | * @return \WP_Error|boolean |
||
82 | */ |
||
83 | View Code Duplication | public static function register( $filepath, $classname ) { |
|
92 | |||
93 | /** |
||
94 | * De-register an existing service |
||
95 | * @param string $filepath |
||
96 | * @return \WP_Error|boolean |
||
97 | */ |
||
98 | View Code Duplication | public static function unregister( $filepath ) { |
|
108 | |||
109 | /** |
||
110 | * Instantiate the individual service classes |
||
111 | * |
||
112 | * @param string $classname |
||
113 | * |
||
114 | * @return array An array of instantiated classes |
||
115 | */ |
||
116 | View Code Duplication | private static function instantiate( $classname ) { |
|
130 | } |
||
131 |
This check marks private properties in classes that are never used. Those properties can be removed.