| Conditions | 3 |
| Paths | 4 |
| Total Lines | 53 |
| 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 |
||
| 18 | private function get_raw_messages() { |
||
| 19 | $messages = array( |
||
| 20 | array( |
||
| 21 | 'id' => 'jpsetup-upload', |
||
| 22 | 'message_path' => '/wp:upload:admin_notices/', |
||
| 23 | 'message' => __( 'Do you want lightning-fast images?', 'jetpack' ), |
||
| 24 | 'description' => __( 'Set up Jetpack, enable Site Accelerator, and start serving your images lightning fast, for free.', 'jetpack' ), |
||
| 25 | 'button_caption' => __( 'Set up Jetpack', 'jetpack' ), |
||
| 26 | ), |
||
| 27 | array( |
||
| 28 | 'id' => 'jpsetup-widgets', |
||
| 29 | 'message_path' => '/wp:widgets:admin_notices/', |
||
| 30 | 'message' => __( 'Looking for even more widgets?', 'jetpack' ), |
||
| 31 | 'description' => __( 'Set up Jetpack for great additional widgets that display business contact info and maps, blog stats, and top posts.', 'jetpack' ), |
||
| 32 | 'button_caption' => __( 'Set up Jetpack', 'jetpack' ), |
||
| 33 | ), |
||
| 34 | ); |
||
| 35 | |||
| 36 | if ( wp_count_posts()->publish >= 5 ) { |
||
| 37 | $messages[] = array( |
||
| 38 | 'id' => 'jpsetup-posts', |
||
| 39 | 'message_path' => '/wp:edit-post:admin_notices/', |
||
| 40 | 'message' => __( 'Do you know which of these posts gets the most traffic?', 'jetpack' ), |
||
| 41 | 'description' => __( 'Set up Jetpack to get in-depth stats about your content and visitors.', 'jetpack' ), |
||
| 42 | 'button_caption' => __( 'Set up Jetpack', 'jetpack' ), |
||
| 43 | ); |
||
| 44 | } |
||
| 45 | |||
| 46 | foreach ( $messages as $key => $message ) { |
||
| 47 | /* |
||
| 48 | * Add Connect URL to each message, with from including jitm id. |
||
| 49 | */ |
||
| 50 | $jetpack_setup_url = Jetpack::init()->build_connect_url( |
||
| 51 | true, |
||
| 52 | false, |
||
| 53 | sprintf( 'pre-connection-jitm-%s', $message['id'] ) |
||
| 54 | ); |
||
| 55 | // Add parameter to URL. Since we mention accepting ToS when clicking, no need to ask again on wpcom. |
||
| 56 | $jetpack_setup_url = add_query_arg( 'auth_approved', 'true', $jetpack_setup_url ); |
||
| 57 | |||
| 58 | $messages[ $key ]['button_link'] = $jetpack_setup_url; |
||
| 59 | |||
| 60 | /* |
||
| 61 | * Add ToS acceptance message to JITM description |
||
| 62 | */ |
||
| 63 | $messages[ $key ]['description'] .= sprintf( |
||
| 64 | '<br /><br />%s', |
||
| 65 | \jetpack_render_tos_blurb( false ) |
||
| 66 | ); |
||
| 67 | } |
||
| 68 | |||
| 69 | return $messages; |
||
| 70 | } |
||
| 71 | |||
| 90 |