| Conditions | 7 |
| Paths | 6 |
| Total Lines | 56 |
| Code Lines | 45 |
| 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 |
||
| 84 | public function render() { |
||
| 85 | $last_query_info = $this->jetpack_search->get_last_query_info(); |
||
| 86 | |||
| 87 | // If not empty, let's reshuffle the order of some things. |
||
| 88 | if ( ! empty( $last_query_info ) ) { |
||
| 89 | $args = $last_query_info['args']; |
||
| 90 | $response = $last_query_info['response']; |
||
| 91 | $response_code = $last_query_info['response_code']; |
||
| 92 | |||
| 93 | unset( $last_query_info['args'] ); |
||
| 94 | unset( $last_query_info['response'] ); |
||
| 95 | unset( $last_query_info['response_code'] ); |
||
| 96 | |||
| 97 | if ( is_null( $last_query_info['es_time'] ) ) { |
||
| 98 | $last_query_info['es_time'] = esc_html_x( |
||
| 99 | 'cache hit', |
||
| 100 | 'displayed in search results when results are cached', |
||
| 101 | 'jetpack' |
||
| 102 | ); |
||
| 103 | } |
||
| 104 | |||
| 105 | $temp = array_merge( |
||
| 106 | array( 'response_code' => $response_code ), |
||
| 107 | array( 'args' => $args ), |
||
| 108 | $last_query_info, |
||
| 109 | array( 'response' => $response ) |
||
| 110 | ); |
||
| 111 | |||
| 112 | $last_query_info = $temp; |
||
| 113 | } |
||
| 114 | ?> |
||
| 115 | <div class="jetpack-search-debug-bar"> |
||
| 116 | <h2><?php esc_html_e( 'Last query information:', 'jetpack' ); ?></h2> |
||
| 117 | <?php if ( empty( $last_query_info ) ) : ?> |
||
| 118 | <?php echo esc_html_x( 'None', 'Text displayed when there is no information', 'jetpack' ); ?> |
||
| 119 | <?php |
||
| 120 | else : |
||
| 121 | foreach ( $last_query_info as $key => $info ) : |
||
|
|
|||
| 122 | ?> |
||
| 123 | <h3><?php echo esc_html( $key ); ?></h3> |
||
| 124 | <?php |
||
| 125 | if ( 'response' !== $key && 'args' !== $key ) : |
||
| 126 | ?> |
||
| 127 | <pre><?php print_r( esc_html( $info ) ); ?></pre> |
||
| 128 | <?php |
||
| 129 | else : |
||
| 130 | $this->render_json_toggle( $info ); |
||
| 131 | endif; |
||
| 132 | ?> |
||
| 133 | <?php |
||
| 134 | endforeach; |
||
| 135 | endif; |
||
| 136 | ?> |
||
| 137 | </div><!-- Closes .jetpack-search-debug-bar --> |
||
| 138 | <?php |
||
| 139 | } |
||
| 140 | |||
| 157 |
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.