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 | class Jetpack_Infinite_Scroll_Extras { |
||
18 | /** |
||
19 | * Class variables |
||
20 | */ |
||
21 | // Oh look, a singleton |
||
22 | private static $__instance = null; |
||
23 | |||
24 | // Option names |
||
25 | private $option_name_google_analytics = 'infinite_scroll_google_analytics'; |
||
26 | |||
27 | /** |
||
28 | * Singleton implementation |
||
29 | * |
||
30 | * @return object |
||
31 | */ |
||
32 | public static function instance() { |
||
38 | |||
39 | /** |
||
40 | * Register actions and filters |
||
41 | * |
||
42 | * @uses add_action, add_filter |
||
43 | * @return null |
||
|
|||
44 | */ |
||
45 | private function __construct() { |
||
56 | |||
57 | /** |
||
58 | * Enable "Configure" button on module card |
||
59 | * |
||
60 | * @uses Jetpack::enable_module_configurable |
||
61 | * @action jetpack_modules_loaded |
||
62 | * @return null |
||
63 | */ |
||
64 | public function action_jetpack_modules_loaded() { |
||
67 | |||
68 | /** |
||
69 | * Register Google Analytics setting |
||
70 | * |
||
71 | * @uses add_settings_field, __, register_setting |
||
72 | * @action admin_init |
||
73 | * @return null |
||
74 | */ |
||
75 | public function action_admin_init() { |
||
79 | |||
80 | /** |
||
81 | * Render Google Analytics option |
||
82 | * |
||
83 | * @uses checked, get_option, __ |
||
84 | * @return html |
||
85 | */ |
||
86 | public function setting_google_analytics() { |
||
90 | |||
91 | /** |
||
92 | * Sanitize value as a boolean |
||
93 | * |
||
94 | * @param mixed $value |
||
95 | * @return bool |
||
96 | */ |
||
97 | public function sanitize_boolean_value( $value ) { |
||
100 | |||
101 | /** |
||
102 | * Load theme's infinite scroll annotation file, if present in the IS plugin. |
||
103 | * The `setup_theme` action is used because the annotation files should be using `after_setup_theme` to register support for IS. |
||
104 | * |
||
105 | * As released in Jetpack 2.0, a child theme's parent wasn't checked for in the plugin's bundled support, hence the convoluted way the parent is checked for now. |
||
106 | * |
||
107 | * @uses is_admin, wp_get_theme, apply_filters |
||
108 | * @action setup_theme |
||
109 | * @return null |
||
110 | */ |
||
111 | function action_after_setup_theme() { |
||
130 | |||
131 | /** |
||
132 | * Modify Infinite Scroll configuration information |
||
133 | * |
||
134 | * @uses Jetpack::get_active_modules, is_user_logged_in, stats_get_options, Jetpack_Options::get_option, get_option, JETPACK__API_VERSION, JETPACK__VERSION |
||
135 | * @filter infinite_scroll_js_settings |
||
136 | * @return array |
||
137 | */ |
||
138 | public function filter_infinite_scroll_js_settings( $settings ) { |
||
167 | |||
168 | /** |
||
169 | * Always load certain scripts when IS is enabled, as they can't be loaded after `document.ready` fires, meaning they can't leverage IS's script loader. |
||
170 | * |
||
171 | * @global $videopress |
||
172 | * @uses do_action() |
||
173 | * @uses apply_filters() |
||
174 | * @uses wp_enqueue_style() |
||
175 | * @uses wp_enqueue_script() |
||
176 | * @action wp_enqueue_scripts |
||
177 | * @return null |
||
178 | */ |
||
179 | public function action_wp_enqueue_scripts() { |
||
219 | } |
||
220 | Jetpack_Infinite_Scroll_Extras::instance(); |
||
231 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.