| Conditions | 14 |
| Paths | 8 |
| Total Lines | 44 |
| Code Lines | 17 |
| 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 |
||
| 152 | public function save_meta_boxes( $post_id, $post ) { |
||
| 153 | |||
| 154 | // $post_id and $post are required. |
||
| 155 | if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
||
| 156 | return; |
||
| 157 | } |
||
| 158 | |||
| 159 | // Don't save meta boxes for revisions or autosaves. |
||
| 160 | if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
||
| 161 | return; |
||
| 162 | } |
||
| 163 | |||
| 164 | // Check the nonce. |
||
| 165 | if ( empty( $_POST['simcal_meta_nonce'] ) || ! wp_verify_nonce( $_POST['simcal_meta_nonce'], 'simcal_save_data' ) ) { |
||
| 166 | return; |
||
| 167 | } |
||
| 168 | |||
| 169 | // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
||
| 170 | if ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) { |
||
| 171 | return; |
||
| 172 | } |
||
| 173 | |||
| 174 | // Check user has permission to edit |
||
| 175 | if ( ! current_user_can( 'edit_post', $post_id ) ) { |
||
| 176 | return; |
||
| 177 | } |
||
| 178 | |||
| 179 | // We need this save event to run once to avoid potential endless loops. |
||
| 180 | // This would have been perfect: |
||
| 181 | // `remove_action( current_filter(), __METHOD__ );` |
||
| 182 | // But cannot be used due to a WordPress bug: |
||
| 183 | // @link https://core.trac.wordpress.org/ticket/17817 |
||
| 184 | // @see also https://github.com/woothemes/woocommerce/issues/6485 |
||
| 185 | self::$saved_meta_boxes = true; |
||
| 186 | |||
| 187 | // Check the post type. |
||
| 188 | if ( 'calendar' == $post->post_type ) { |
||
| 189 | do_action( 'simcal_save_settings_meta', $post_id, $post ); |
||
| 190 | } elseif ( in_array( $post->post_type, $this->post_types ) ) { |
||
| 191 | do_action( 'simcal_save_attach_calendar_meta', $post_id, $post ); |
||
| 192 | } |
||
| 193 | |||
| 194 | do_action( 'simcal_save_meta_boxes', $post_id, $post ); |
||
| 195 | } |
||
| 196 | |||
| 198 |
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.