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