Conditions | 5 |
Paths | 16 |
Total Lines | 112 |
Code Lines | 80 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
86 | 'exercise', |
||
87 | 'meal', |
||
88 | 'recipe', |
||
89 | //'tip', |
||
90 | 'recipe', |
||
91 | ); |
||
92 | |||
93 | foreach ( $this->post_types as $post_type ) { |
||
94 | $this->$post_type = require_once LSX_HEALTH_PLAN_PATH . 'classes/admin/settings/class-' . $post_type . '.php'; |
||
95 | } |
||
96 | |||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Hook in and register a submenu options page for the Page post-type menu. |
||
101 | */ |
||
102 | public function register_settings_page() { |
||
103 | $cmb = new_cmb2_box( |
||
104 | array( |
||
105 | 'id' => $this->screen_id, |
||
106 | 'title' => esc_html__( 'Settings', 'lsx-health-plan' ), |
||
107 | 'object_types' => array( 'options-page' ), |
||
108 | 'option_key' => 'lsx_health_plan_options', // The option key and admin menu page slug. |
||
109 | 'parent_slug' => 'edit.php?post_type=plan', // Make options page a submenu item of the themes menu. |
||
110 | 'capability' => 'manage_options', // Cap required to view options-page. |
||
111 | ) |
||
112 | ); |
||
113 | do_action( 'lsx_hp_settings_page', $cmb ); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Registers the general settings. |
||
118 | * |
||
119 | * @param object $cmb new_cmb2_box(). |
||
120 | * @return void |
||
121 | */ |
||
122 | public function general_settings( $cmb ) { |
||
123 | $cmb->add_field( |
||
124 | array( |
||
125 | 'name' => __( 'Exercises', 'lsx-health-plan' ), |
||
126 | 'id' => 'exercise_enabled', |
||
127 | 'type' => 'checkbox', |
||
128 | 'value' => 1, |
||
129 | 'default' => 0, |
||
130 | 'description' => __( 'Enabling the exercise post type will automatically replace the Video post type.', 'lsx-health-plan' ), |
||
131 | ) |
||
132 | ); |
||
133 | |||
134 | $cmb->add_field( |
||
135 | array( |
||
136 | 'name' => __( 'Disable Workouts', 'lsx-health-plan' ), |
||
137 | 'id' => 'workout_disabled', |
||
138 | 'type' => 'checkbox', |
||
139 | 'value' => 1, |
||
140 | 'default' => 0, |
||
141 | 'description' => __( 'Disable workout post type if you are wanting a minimal site.', 'lsx-health-plan' ), |
||
142 | ) |
||
143 | ); |
||
144 | |||
145 | $cmb->add_field( |
||
146 | array( |
||
147 | 'name' => __( 'Disable Recipes', 'lsx-health-plan' ), |
||
148 | 'id' => 'recipe_disabled', |
||
149 | 'type' => 'checkbox', |
||
150 | 'value' => 1, |
||
151 | 'default' => 0, |
||
152 | 'description' => __( 'Disable recipe post type if you are wanting a minimal site.', 'lsx-health-plan' ), |
||
153 | ) |
||
154 | ); |
||
155 | |||
156 | $cmb->add_field( |
||
157 | array( |
||
158 | 'name' => __( 'Disable Meals', 'lsx-health-plan' ), |
||
159 | 'id' => 'meal_disabled', |
||
160 | 'type' => 'checkbox', |
||
161 | 'value' => 1, |
||
162 | 'default' => 0, |
||
163 | 'description' => __( 'Disable meal post type if you are wanting a minimal site.', 'lsx-health-plan' ), |
||
164 | ) |
||
165 | ); |
||
166 | |||
167 | |||
168 | $cmb->add_field( |
||
169 | array( |
||
170 | 'name' => __( 'Login Slug', 'lsx-health-plan' ), |
||
171 | 'id' => 'login_slug', |
||
172 | 'type' => 'input', |
||
173 | 'value' => '', |
||
174 | 'default' => 'login', |
||
175 | 'after_row' => __( '<p style="font-style: italic;">If you have changed any URL slugs, please remember re-save your permalinks in Settings > Permalinks.</p>', 'lsx-health-plan' ), |
||
176 | ) |
||
177 | ); |
||
178 | |||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Enable Business Directory Search settings only if LSX Search plugin is enabled. |
||
183 | * |
||
184 | * @param object $cmb The CMB2() class. |
||
185 | * @param string $section either engine,archive or single. |
||
186 | * @return void |
||
187 | */ |
||
188 | public function generate_tabs( $cmb ) { |
||
189 | $tabs = $this->get_settings_tabs(); |
||
190 | |||
191 | foreach ( $tabs as $tab_key => $tab ) { |
||
192 | $cmb->add_field( |
||
193 | array( |
||
194 | 'id' => 'settings_' . $tab_key . '_title', |
||
195 | 'type' => 'title', |
||
196 | 'name' => $tab['title'], |
||
197 | 'default' => $tab['title'], |
||
198 | 'description' => $tab['desc'], |
||
269 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.