| Conditions | 2 |
| Paths | 2 |
| Total Lines | 55 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 29 | static function dashboard_ui() { |
||
| 30 | if ( ! current_user_can( 'manage_options' ) ) |
||
| 31 | wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) ); |
||
| 32 | |||
| 33 | $strings = json_encode( array( |
||
| 34 | 'WAITING' => array( |
||
| 35 | 'action' => __( 'Refresh Status', 'jetpack' ), |
||
| 36 | 'status' => __( 'Indexing request queued and waiting…', 'jetpack' ), |
||
| 37 | ), |
||
| 38 | 'INDEXING' => array( |
||
| 39 | 'action' => __( 'Refresh Status', 'jetpack' ), |
||
| 40 | 'status' => __( 'Indexing posts', 'jetpack' ), |
||
| 41 | ), |
||
| 42 | 'DONE' => array( |
||
| 43 | 'action' => __( 'Reindex Posts', 'jetpack' ), |
||
| 44 | 'status' => __( 'Posts indexed.', 'jetpack' ), |
||
| 45 | ), |
||
| 46 | 'ERROR' => array( |
||
| 47 | 'action' => __( 'Refresh Status', 'jetpack' ), |
||
| 48 | 'status' => __( 'Status unknown.', 'jetpack' ), |
||
| 49 | ), |
||
| 50 | 'ERROR:LARGE' => array( |
||
| 51 | 'action' => __( 'Refresh Status', 'jetpack' ), |
||
| 52 | 'status' => __( 'This site is too large, please contact Jetpack support to sync.', 'jetpack' ), |
||
| 53 | ), |
||
| 54 | ) ); |
||
| 55 | |||
| 56 | wp_enqueue_script( |
||
| 57 | 'jetpack_sync_reindex_control', |
||
| 58 | plugins_url( '_inc/jquery.jetpack-sync.js', JETPACK__PLUGIN_FILE ), |
||
| 59 | array( 'jquery' ), |
||
| 60 | JETPACK__VERSION |
||
| 61 | ); |
||
| 62 | |||
| 63 | // $template = <<<EOT |
||
| 64 | // <p class="jetpack_sync_reindex_control" id="jetpack_sync_reindex_control" data-strings="%s"> |
||
| 65 | // <input type="submit" class="jetpack_sync_reindex_control_action button" value="%s" disabled /> |
||
| 66 | // <span class="jetpack_sync_reindex_control_status">…</span> |
||
| 67 | // </p> |
||
| 68 | // EOT; |
||
| 69 | |||
| 70 | $template = <<<EOT |
||
| 71 | <p class="jetpack_sync_reindex_control" id="jetpack_sync_reindex_control" data-strings="%s"> |
||
| 72 | This is a test |
||
| 73 | <input type="submit" class="jetpack_sync_reindex_control_action button" value="%s" disabled /> |
||
| 74 | <span class="jetpack_sync_reindex_control_status">…</span> |
||
| 75 | </p> |
||
| 76 | EOT; |
||
| 77 | |||
| 78 | echo sprintf( |
||
| 79 | $template, |
||
| 80 | esc_attr( $strings ), |
||
| 81 | esc_attr__( 'Refresh Status', 'jetpack' ) |
||
| 82 | ); |
||
| 83 | } |
||
| 84 | |||
| 86 |