Conditions | 5 |
Paths | 2 |
Total Lines | 62 |
Lines | 9 |
Ratio | 14.52 % |
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 | $core_tests['direct'][ $test['name'] ] = array( |
||
35 | 'label' => __( 'Jetpack: ', 'jetpack' ) . $test['name'], |
||
36 | 'test' => function() use ( $test, $cxn_tests ) { // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewClosure.Found |
||
37 | $results = $cxn_tests->run_test( $test['name'] ); |
||
38 | // Test names are, by default, `test__some_string_of_text`. Let's convert to "Some String Of Text" for humans. |
||
39 | $label = ucwords( |
||
40 | str_replace( |
||
41 | '_', |
||
42 | ' ', |
||
43 | str_replace( 'test__', '', $test['name'] ) |
||
44 | ) |
||
45 | ); |
||
46 | $return = array( |
||
47 | 'label' => $label, |
||
48 | 'status' => 'good', |
||
49 | 'badge' => array( |
||
50 | 'label' => __( 'Jetpack', 'jetpack' ), |
||
51 | 'color' => 'green', |
||
52 | ), |
||
53 | 'description' => sprintf( |
||
54 | '<p>%s</p>', |
||
55 | __( 'This test successfully passed!', 'jetpack' ) |
||
56 | ), |
||
57 | 'actions' => '', |
||
58 | 'test' => 'jetpack_' . $test['name'], |
||
59 | ); |
||
60 | if ( is_wp_error( $results ) ) { |
||
61 | return; |
||
62 | } |
||
63 | if ( false === $results['pass'] ) { |
||
64 | $return['label'] = $results['message']; |
||
65 | $return['status'] = $results['severity']; |
||
66 | $return['description'] = sprintf( |
||
67 | '<p>%s</p>', |
||
68 | $results['resolution'] |
||
69 | ); |
||
70 | View Code Duplication | if ( ! empty( $results['action'] ) ) { |
|
71 | $return['actions'] = sprintf( |
||
72 | '<a class="button button-primary" 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>', |
||
73 | esc_url( $results['action'] ), |
||
74 | __( 'Resolve', 'jetpack' ), |
||
75 | /* translators: accessibility text */ |
||
76 | __( '(opens in a new tab)', 'jetpack' ) |
||
77 | ); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | return $return; |
||
82 | }, |
||
83 | ); |
||
84 | } |
||
85 | $core_tests['async']['jetpack_test_suite'] = array( |
||
86 | 'label' => __( 'Jetpack Tests', 'jetpack' ), |
||
87 | 'test' => 'jetpack_local_testing_suite', |
||
88 | ); |
||
89 | |||
90 | return $core_tests; |
||
91 | } |
||
92 | |||
93 |