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 |
||
6 | abstract class Jetpack_JSON_API_Modules_Endpoint extends Jetpack_JSON_API_Endpoint { |
||
7 | |||
8 | protected $modules = array(); |
||
9 | |||
10 | protected $bulk = true; |
||
11 | |||
12 | static $_response_format = array( |
||
|
|||
13 | 'id' => '(string) The module\'s ID', |
||
14 | 'active' => '(boolean) The module\'s status.', |
||
15 | 'name' => '(string) The module\'s name.', |
||
16 | 'description' => '(safehtml) The module\'s description.', |
||
17 | 'sort' => '(int) The module\'s display order.', |
||
18 | 'introduced' => '(string) The Jetpack version when the module was introduced.', |
||
19 | 'changed' => '(string) The Jetpack version when the module was changed.', |
||
20 | 'free' => '(boolean) The module\'s Free or Paid status.', |
||
21 | 'module_tags' => '(array) The module\'s tags.', |
||
22 | 'override' => '(string) The module\'s override. Empty if no override, otherwise \'active\' or \'inactive\'', |
||
23 | ); |
||
24 | |||
25 | protected function result() { |
||
36 | |||
37 | /** |
||
38 | * Walks through either the submitted modules or list of themes and creates the global array |
||
39 | * @param $theme |
||
40 | * |
||
41 | * @return bool |
||
42 | */ |
||
43 | protected function validate_input( $module) { |
||
67 | |||
68 | /** |
||
69 | * Walks through submitted themes to make sure they are valid |
||
70 | * @return bool|WP_Error |
||
71 | */ |
||
72 | protected function validate_modules() { |
||
80 | |||
81 | protected static function format_module( $module_slug ) { |
||
106 | |||
107 | /** |
||
108 | * Format a list of modules for public display, using the supplied offset and limit args |
||
109 | * @uses WPCOM_JSON_API_Endpoint::query_args() |
||
110 | * @return array Public API modules objects |
||
111 | */ |
||
112 | View Code Duplication | protected function get_modules() { |
|
124 | |||
125 | } |
||
126 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.