| Conditions | 18 |
| Paths | 19 |
| Total Lines | 84 |
| Code Lines | 62 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 61 | public function render( $field, $value, $object_id, $object_type, $field_type ) { |
||
| 62 | $this->setup_admin_scripts(); |
||
| 63 | $field_name = $field->_name(); |
||
| 64 | |||
| 65 | if ( $field->args( 'limit' ) > 1 ) { |
||
| 66 | |||
| 67 | echo '<ul class="cmb-post-search-ajax-results" id="' . $field_name . '_results">'; |
||
| 68 | if ( isset( $value ) && ! empty( $value ) ) { |
||
| 69 | if ( ! is_array( $value ) ) { |
||
| 70 | $value = array( $value ); |
||
| 71 | } |
||
| 72 | $value = array_unique( $value ); |
||
| 73 | foreach ( $value as $val ) { |
||
| 74 | $handle = ( $field->args( 'sortable' ) ) ? '<span class="hndl"></span>' : ''; |
||
| 75 | $li_css = ''; |
||
| 76 | if ( $field->args( 'object_type' ) == 'user' ) { |
||
| 77 | $guid = get_edit_user_link( $val ); |
||
| 78 | $user = get_userdata( $val ); |
||
| 79 | $title = $user->display_name; |
||
| 80 | } else { |
||
| 81 | $guid = get_edit_post_link( $val ); |
||
| 82 | $title = get_the_title( $val ); |
||
| 83 | if ( 'trash' === get_post_status( $val ) ) { |
||
| 84 | $li_css = 'display:none;'; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | echo '<li style="' . $li_css . '">' . $handle . '<input type="hidden" name="' . $field_name . '_results[]" value="' . $val . '"><a href="' . $guid . '" target="_blank" class="edit-link">' . $title . '</a><a class="remover"><span class="dashicons dashicons-no"></span><span class="dashicons dashicons-dismiss"></span></a></li>'; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | echo '</ul>'; |
||
| 91 | $field_value = ''; |
||
| 92 | } else { |
||
| 93 | if ( is_array( $value ) ) { |
||
| 94 | $value = $value[0]; |
||
| 95 | } |
||
| 96 | if ( $field->args( 'object_type' ) == 'user' ) { |
||
| 97 | $field_value = ( $value ? get_userdata( $value )->display_name : '' ); |
||
| 98 | } else { |
||
| 99 | $field_value = ( $value ? get_the_title( $value ) : '' ); |
||
| 100 | } |
||
| 101 | echo $field_type->input( |
||
| 102 | array( |
||
| 103 | 'type' => 'hidden', |
||
| 104 | 'name' => $field_name . '_results', |
||
| 105 | 'value' => $value, |
||
| 106 | 'desc' => false, |
||
| 107 | ) |
||
| 108 | ); |
||
| 109 | if ( isset( $field->group ) ) { |
||
| 110 | $store_name = str_replace( '][', '_', $field_name ); |
||
| 111 | $store_name = str_replace( ']', '', $store_name ); |
||
| 112 | $store_name = str_replace( '[', '_', $store_name ); |
||
| 113 | |||
| 114 | echo $field_type->input( |
||
| 115 | array( |
||
| 116 | 'type' => 'hidden', |
||
| 117 | 'id' => $field_name . '_store', |
||
| 118 | 'name' => $store_name . '_store', |
||
| 119 | 'class' => 'cmb-post-search-ajax-store', |
||
| 120 | 'value' => $value, |
||
| 121 | 'desc' => false, |
||
| 122 | ) |
||
| 123 | ); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | echo $field_type->input( |
||
| 128 | array( |
||
| 129 | 'type' => 'text', |
||
| 130 | 'name' => $field_name, |
||
| 131 | 'id' => $field_name, |
||
| 132 | 'class' => 'cmb-post-search-ajax', |
||
| 133 | 'value' => $field_value, |
||
| 134 | 'desc' => false, |
||
| 135 | 'data-limit' => $field->args( 'limit' ) ? $field->args( 'limit' ) : '1', |
||
| 136 | 'data-sortable' => $field->args( 'sortable' ) ? $field->args( 'sortable' ) : '0', |
||
| 137 | 'data-object' => $field->args( 'object_type' ) ? $field->args( 'object_type' ) : 'post', |
||
| 138 | 'data-queryargs'=> $field->args( 'query_args' ) ? htmlspecialchars( json_encode( $field->args( 'query_args' ) ), ENT_QUOTES, 'UTF-8' ) : '' |
||
| 139 | ) |
||
| 140 | ); |
||
| 141 | |||
| 142 | echo '<img src="' . admin_url( 'images/spinner.gif' ) . '" class="cmb-post-search-ajax-spinner" />'; |
||
| 143 | |||
| 144 | $field_type->_desc( true, true ); |
||
| 145 | |||
| 285 |