Conditions | 8 |
Paths | 7 |
Total Lines | 61 |
Code Lines | 48 |
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 |
||
77 | public function render() { |
||
78 | if ( ! class_exists( 'Jetpack_Search' ) ) { |
||
79 | return; |
||
80 | } |
||
81 | |||
82 | $jetpack_search = Jetpack_Search::instance(); |
||
83 | $last_query_info = $jetpack_search->get_last_query_info(); |
||
84 | |||
85 | // If not empty, let's reshuffle the order of some things. |
||
86 | if ( ! empty( $last_query_info ) ) { |
||
87 | $args = $last_query_info['args']; |
||
88 | $response = $last_query_info['response']; |
||
89 | $response_code = $last_query_info['response_code']; |
||
90 | |||
91 | unset( $last_query_info['args'] ); |
||
92 | unset( $last_query_info['response'] ); |
||
93 | unset( $last_query_info['response_code'] ); |
||
94 | |||
95 | if ( is_null( $last_query_info['es_time'] ) ) { |
||
96 | $last_query_info['es_time'] = esc_html_x( |
||
97 | 'cache hit', |
||
98 | 'displayed in search results when results are cached', |
||
99 | 'jetpack' |
||
100 | ); |
||
101 | } |
||
102 | |||
103 | $temp = array_merge( |
||
104 | array( 'response_code' => $response_code ), |
||
105 | array( 'args' => $args ), |
||
106 | $last_query_info, |
||
107 | array( 'response' => $response ) |
||
108 | ); |
||
109 | |||
110 | $last_query_info = $temp; |
||
111 | } |
||
112 | ?> |
||
113 | <div class="jetpack-search-debug-bar"> |
||
114 | <h2><?php esc_html_e( 'Last query information:', 'jetpack' ); ?></h2> |
||
115 | <?php if ( empty( $last_query_info ) ) : ?> |
||
116 | <?php echo esc_html_x( 'None', 'Text displayed when there is no information', 'jetpack' ); ?> |
||
117 | <?php |
||
118 | else : |
||
119 | foreach ( $last_query_info as $key => $info ) : |
||
|
|||
120 | ?> |
||
121 | <h3><?php echo esc_html( $key ); ?></h3> |
||
122 | <?php |
||
123 | if ( 'response' !== $key && 'args' !== $key ) : |
||
124 | ?> |
||
125 | <pre><?php print_r( esc_html( $info ) ); ?></pre> |
||
126 | <?php |
||
127 | else : |
||
128 | $this->render_json_toggle( $info ); |
||
129 | endif; |
||
130 | ?> |
||
131 | <?php |
||
132 | endforeach; |
||
133 | endif; |
||
134 | ?> |
||
135 | </div><!-- Closes .jetpack-search-debug-bar --> |
||
136 | <?php |
||
137 | } |
||
138 | |||
155 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.