| Conditions | 2 |
| Paths | 2 |
| Total Lines | 60 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 50 | static function dashboard_ui() { |
||
| 51 | if ( ! current_user_can( 'manage_options' ) ) |
||
| 52 | wp_die( esc_html__('You do not have sufficient permissions to access this page.', 'jetpack' ) ); |
||
| 53 | |||
| 54 | $strings = json_encode( array( |
||
| 55 | 'WAITING' => array( |
||
| 56 | 'action' => __( 'Refresh Status', 'jetpack' ), |
||
| 57 | 'status' => __( 'Indexing request queued and waiting…', 'jetpack' ), |
||
| 58 | ), |
||
| 59 | 'INDEXING' => array( |
||
| 60 | 'action' => __( 'Refresh Status', 'jetpack' ), |
||
| 61 | 'status' => __( 'Indexing posts', 'jetpack' ), |
||
| 62 | ), |
||
| 63 | 'DONE' => array( |
||
| 64 | 'action' => __( 'Reindex Posts', 'jetpack' ), |
||
| 65 | 'status' => __( 'Posts indexed.', 'jetpack' ), |
||
| 66 | ), |
||
| 67 | 'ERROR' => array( |
||
| 68 | 'action' => __( 'Refresh Status', 'jetpack' ), |
||
| 69 | 'status' => __( 'Status unknown.', 'jetpack' ), |
||
| 70 | ), |
||
| 71 | 'ERROR:LARGE' => array( |
||
| 72 | 'action' => __( 'Refresh Status', 'jetpack' ), |
||
| 73 | 'status' => __( 'This site is too large, please contact Jetpack support to sync.', 'jetpack' ), |
||
| 74 | ), |
||
| 75 | ) ); |
||
| 76 | |||
| 77 | wp_enqueue_script( |
||
| 78 | 'jetpack_sync_reindex_control', |
||
| 79 | plugins_url( '_inc/jetpack-sync.js', JETPACK__PLUGIN_FILE ), |
||
| 80 | array( 'jquery' ), |
||
| 81 | JETPACK__VERSION |
||
| 82 | ); |
||
| 83 | |||
| 84 | // $template = <<<EOT |
||
| 85 | // <p class="jetpack_sync_reindex_control" id="jetpack_sync_reindex_control" data-strings="%s"> |
||
| 86 | // <input type="submit" class="jetpack_sync_reindex_control_action button" value="%s" disabled /> |
||
| 87 | // <span class="jetpack_sync_reindex_control_status">…</span> |
||
| 88 | // </p> |
||
| 89 | // EOT; |
||
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | $template = <<<EOT |
||
| 94 | <div id="sync_status"> |
||
| 95 | Sync status: |
||
| 96 | </div> |
||
| 97 | <p class="jetpack_sync_reindex_control" id="jetpack_sync_reindex_control" data-strings="%s"> |
||
| 98 | This is a test |
||
| 99 | <input type="submit" class="jetpack_sync_reindex_control_action button" value="%s" disabled /> |
||
| 100 | <span class="jetpack_sync_reindex_control_status">…</span> |
||
| 101 | </p> |
||
| 102 | EOT; |
||
| 103 | |||
| 104 | echo sprintf( |
||
| 105 | $template, |
||
| 106 | esc_attr( $strings ), |
||
| 107 | esc_attr__( 'Refresh Status', 'jetpack' ) |
||
| 108 | ); |
||
| 109 | } |
||
| 110 | |||
| 112 |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exitexpression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.