Conditions | 18 |
Paths | 19 |
Total Lines | 84 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 |
||
37 | public function render( $field, $value, $object_id, $object_type, $field_type ) { |
||
38 | $this->setup_admin_scripts(); |
||
39 | $field_name = $field->_name(); |
||
40 | |||
41 | if ( $field->args( 'limit' ) > 1 ) { |
||
42 | |||
43 | echo '<ul class="cmb-post-search-ajax-results" id="' . $field_name . '_results">'; |
||
44 | if ( isset( $value ) && ! empty( $value ) ) { |
||
45 | if ( ! is_array( $value ) ) { |
||
46 | $value = array( $value ); |
||
47 | } |
||
48 | $value = array_unique( $value ); |
||
49 | foreach ( $value as $val ) { |
||
50 | $handle = ( $field->args( 'sortable' ) ) ? '<span class="hndl"></span>' : ''; |
||
51 | $li_css = ''; |
||
52 | if ( $field->args( 'object_type' ) == 'user' ) { |
||
53 | $guid = get_edit_user_link( $val ); |
||
54 | $user = get_userdata( $val ); |
||
55 | $title = $user->display_name; |
||
56 | } else { |
||
57 | $guid = get_edit_post_link( $val ); |
||
58 | $title = get_the_title( $val ); |
||
59 | if ( 'trash' === get_post_status( $val ) ) { |
||
60 | $li_css = 'display:none;'; |
||
61 | } |
||
62 | } |
||
63 | 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>'; |
||
64 | } |
||
65 | } |
||
66 | echo '</ul>'; |
||
67 | $field_value = ''; |
||
68 | } else { |
||
69 | if ( is_array( $value ) ) { |
||
70 | $value = $value[0]; |
||
71 | } |
||
72 | if ( $field->args( 'object_type' ) == 'user' ) { |
||
73 | $field_value = ( $value ? get_userdata( $value )->display_name : '' ); |
||
74 | } else { |
||
75 | $field_value = ( $value ? get_the_title( $value ) : '' ); |
||
76 | } |
||
77 | echo $field_type->input( |
||
78 | array( |
||
79 | 'type' => 'hidden', |
||
80 | 'name' => $field_name . '_results', |
||
81 | 'value' => $value, |
||
82 | 'desc' => false, |
||
83 | ) |
||
84 | ); |
||
85 | if ( isset( $field->group ) ) { |
||
86 | $store_name = str_replace( '][', '_', $field_name ); |
||
87 | $store_name = str_replace( ']', '', $store_name ); |
||
88 | $store_name = str_replace( '[', '_', $store_name ); |
||
89 | |||
90 | echo $field_type->input( |
||
91 | array( |
||
92 | 'type' => 'hidden', |
||
93 | 'id' => $field_name . '_store', |
||
94 | 'name' => $store_name . '_store', |
||
95 | 'class' => 'cmb-post-search-ajax-store', |
||
96 | 'value' => $value, |
||
97 | 'desc' => false, |
||
98 | ) |
||
99 | ); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | echo $field_type->input( |
||
104 | array( |
||
105 | 'type' => 'text', |
||
106 | 'name' => $field_name, |
||
107 | 'id' => $field_name, |
||
108 | 'class' => 'cmb-post-search-ajax', |
||
109 | 'value' => $field_value, |
||
110 | 'desc' => false, |
||
111 | 'data-limit' => $field->args( 'limit' ) ? $field->args( 'limit' ) : '1', |
||
112 | 'data-sortable' => $field->args( 'sortable' ) ? $field->args( 'sortable' ) : '0', |
||
113 | 'data-object' => $field->args( 'object_type' ) ? $field->args( 'object_type' ) : 'post', |
||
114 | 'data-queryargs'=> $field->args( 'query_args' ) ? htmlspecialchars( json_encode( $field->args( 'query_args' ) ), ENT_QUOTES, 'UTF-8' ) : '' |
||
115 | ) |
||
116 | ); |
||
117 | |||
118 | echo '<img src="' . admin_url( 'images/spinner.gif' ) . '" class="cmb-post-search-ajax-spinner" />'; |
||
119 | |||
120 | $field_type->_desc( true, true ); |
||
121 | |||
261 |