Conditions | 4 |
Paths | 4 |
Total Lines | 147 |
Code Lines | 99 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
120 | public function details_metabox() { |
||
121 | |||
122 | $prefix = 'lsx_'; |
||
123 | |||
124 | $users = get_transient( 'lsx_team_users' ); |
||
125 | |||
126 | if ( false === $users || '' === $users ) { |
||
127 | $users = get_users( array( |
||
128 | 'role__in' => array( 'administrator', 'editor', 'author' ), |
||
129 | ) ); |
||
130 | set_transient( 'lsx_team_users', $users, 5 * 60 ); |
||
131 | } |
||
132 | |||
133 | foreach ( $users as $user ) { |
||
134 | $user_array[$user->ID] = $user->user_login; |
||
135 | } |
||
136 | |||
137 | $cmb = new_cmb2_box( |
||
138 | array( |
||
139 | 'id' => $prefix . '_team', |
||
140 | 'title' => esc_html__( 'Team Member Details', 'lsx-team' ), |
||
141 | 'object_types' => 'team', |
||
142 | 'context' => 'normal', |
||
143 | 'priority' => 'low', |
||
144 | 'show_names' => true, |
||
145 | ) |
||
146 | ); |
||
147 | |||
148 | $cmb->add_field( |
||
149 | array( |
||
150 | 'name' => esc_html__( 'Featured:', 'lsx-team' ), |
||
151 | 'id' => $prefix . 'featured', |
||
152 | 'type' => 'checkbox', |
||
153 | 'value' => 1, |
||
154 | 'default' => 0, |
||
155 | 'show_in_rest' => true, |
||
156 | ) |
||
157 | ); |
||
158 | |||
159 | $cmb->add_field( |
||
160 | array( |
||
161 | 'name' => esc_html__( 'Site User', 'lsx-team' ), |
||
162 | 'id' => $prefix . 'site_user', |
||
163 | 'allow_none' => true, |
||
164 | 'type' => 'select', |
||
165 | 'options' => $user_array, |
||
166 | 'show_in_rest' => true, |
||
167 | ) |
||
168 | ); |
||
169 | |||
170 | $cmb->add_field( |
||
171 | array( |
||
172 | 'name' => esc_html__( 'Job Title:', 'lsx-team' ), |
||
173 | 'id' => $prefix . 'job_title', |
||
174 | 'type' => 'text', |
||
175 | 'show_in_rest' => true, |
||
176 | ) |
||
177 | ); |
||
178 | |||
179 | $cmb->add_field( |
||
180 | array( |
||
181 | 'name' => esc_html__( 'Location:', 'lsx-team' ), |
||
182 | 'id' => $prefix . 'location', |
||
183 | 'type' => 'text', |
||
184 | 'show_in_rest' => true, |
||
185 | ) |
||
186 | ); |
||
187 | |||
188 | $cmb->add_field( |
||
189 | array( |
||
190 | 'name' => esc_html__( 'Contact Email Address:', 'lsx-team' ), |
||
191 | 'id' => $prefix . 'email_contact', |
||
192 | 'type' => 'text', |
||
193 | 'show_in_rest' => true, |
||
194 | ) |
||
195 | ); |
||
196 | |||
197 | $cmb->add_field( |
||
198 | array( |
||
199 | 'name' => esc_html__( 'Gravatar Email Address:', 'lsx-team' ), |
||
200 | 'desc' => esc_html__( 'Used for Gravatar if a featured image is not set', 'lsx-team' ), |
||
201 | 'id' => $prefix . 'email_gravatar', |
||
202 | 'type' => 'text', |
||
203 | 'show_in_rest' => true, |
||
204 | ) |
||
205 | ); |
||
206 | |||
207 | $cmb->add_field( |
||
208 | array( |
||
209 | 'name' => esc_html__( 'Telephone Number:', 'lsx-team' ), |
||
210 | 'id' => $prefix . 'tel', |
||
211 | 'type' => 'text', |
||
212 | 'show_in_rest' => true, |
||
213 | ) |
||
214 | ); |
||
215 | |||
216 | $cmb->add_field( |
||
217 | array( |
||
218 | 'name' => esc_html__( 'Skype Name:', 'lsx-team' ), |
||
219 | 'id' => $prefix . 'skype', |
||
220 | 'type' => 'text', |
||
221 | 'show_in_rest' => true, |
||
222 | ) |
||
223 | ); |
||
224 | |||
225 | $cmb->add_field( |
||
226 | array( |
||
227 | 'name' => esc_html__( 'Facebook URL', 'lsx-team' ), |
||
228 | 'id' => $prefix . 'facebook', |
||
229 | 'type' => 'text_url', |
||
230 | 'show_in_rest' => true, |
||
231 | ) |
||
232 | ); |
||
233 | |||
234 | $cmb->add_field( |
||
235 | array( |
||
236 | 'name' => esc_html__( 'Twitter URL', 'lsx-team' ), |
||
237 | 'id' => $prefix . 'twitter', |
||
238 | 'type' => 'text_url', |
||
239 | 'show_in_rest' => true, |
||
240 | ) |
||
241 | ); |
||
242 | |||
243 | $cmb->add_field( |
||
244 | array( |
||
245 | 'name' => esc_html__( 'LinkedIn URL', 'lsx-team' ), |
||
246 | 'id' => $prefix . 'linkedin', |
||
247 | 'type' => 'text_url', |
||
248 | 'show_in_rest' => true, |
||
249 | ) |
||
250 | ); |
||
251 | |||
252 | $cmb->add_field( |
||
253 | array( |
||
254 | 'name' => esc_html__( 'Github URL', 'lsx-team' ), |
||
255 | 'id' => $prefix . 'github', |
||
256 | 'type' => 'text_url', |
||
257 | 'show_in_rest' => true, |
||
258 | ) |
||
259 | ); |
||
260 | |||
261 | $cmb->add_field( |
||
262 | array( |
||
263 | 'name' => esc_html__( 'WordPress URL', 'lsx-team' ), |
||
264 | 'id' => $prefix . 'wordpress', |
||
265 | 'type' => 'text_url', |
||
266 | 'show_in_rest' => true, |
||
267 | ) |
||
456 |