| Conditions | 8 |
| Paths | 2 |
| Total Lines | 72 |
| Lines | 9 |
| Ratio | 12.5 % |
| 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 |
||
| 31 | function jetpack_debugger_site_status_tests( $core_tests ) { |
||
| 32 | $cxn_tests = new Jetpack_Cxn_Tests(); |
||
| 33 | $tests = $cxn_tests->list_tests( 'direct' ); |
||
| 34 | foreach ( $tests as $test ) { |
||
| 35 | |||
| 36 | $core_tests['direct'][ $test['name'] ] = array( |
||
| 37 | 'label' => __( 'Jetpack: ', 'jetpack' ) . $test['name'], |
||
| 38 | 'test' => function() use ( $test, $cxn_tests ) { // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewClosure.Found |
||
| 39 | $results = $cxn_tests->run_test( $test['name'] ); |
||
| 40 | if ( is_wp_error( $results ) ) { |
||
| 41 | return; |
||
| 42 | } |
||
| 43 | |||
| 44 | $label = $results['label'] ? |
||
| 45 | $results['label'] : |
||
| 46 | ucwords( |
||
| 47 | str_replace( |
||
| 48 | '_', |
||
| 49 | ' ', |
||
| 50 | str_replace( 'test__', '', $test['name'] ) |
||
| 51 | ) |
||
| 52 | ); |
||
| 53 | if ( $results['long_description'] ) { |
||
| 54 | $description = $results['long_description']; |
||
| 55 | } elseif ( $results['short_description'] ) { |
||
| 56 | $description = sprintf( |
||
| 57 | '<p>%s</p>', |
||
| 58 | $results['short_description'] |
||
| 59 | ); |
||
| 60 | } else { |
||
| 61 | $description = sprintf( |
||
| 62 | '<p>%s</p>', |
||
| 63 | __( 'This test successfully passed!', 'jetpack' ) |
||
| 64 | ); |
||
| 65 | } |
||
| 66 | |||
| 67 | $return = array( |
||
| 68 | 'label' => $label, |
||
| 69 | 'status' => 'good', |
||
| 70 | 'badge' => array( |
||
| 71 | 'label' => __( 'Jetpack', 'jetpack' ), |
||
| 72 | 'color' => 'green', |
||
| 73 | ), |
||
| 74 | 'description' => $description, |
||
| 75 | 'actions' => '', |
||
| 76 | 'test' => 'jetpack_' . $test['name'], |
||
| 77 | ); |
||
| 78 | |||
| 79 | if ( false === $results['pass'] ) { |
||
| 80 | $return['status'] = $results['severity']; |
||
| 81 | View Code Duplication | if ( ! empty( $results['action'] ) ) { |
|
| 82 | $return['actions'] = sprintf( |
||
| 83 | '<a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s <span class="screen-reader-text">%3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', |
||
| 84 | esc_url( $results['action'] ), |
||
| 85 | $results['action_label'], |
||
| 86 | /* translators: accessibility text */ |
||
| 87 | __( '(opens in a new tab)', 'jetpack' ) |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | return $return; |
||
| 93 | }, |
||
| 94 | ); |
||
| 95 | } |
||
| 96 | $core_tests['async']['jetpack_test_suite'] = array( |
||
| 97 | 'label' => __( 'Jetpack Tests', 'jetpack' ), |
||
| 98 | 'test' => 'jetpack_local_testing_suite', |
||
| 99 | ); |
||
| 100 | |||
| 101 | return $core_tests; |
||
| 102 | } |
||
| 103 | |||
| 177 |