| Conditions | 1 |
| Paths | 1 |
| Total Lines | 201 |
| Code Lines | 192 |
| 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 |
||
| 245 | public function repeater_js_template() { |
||
| 246 | ?> |
||
| 247 | <script type="text/html" class="customize-control-repeater-content"> |
||
| 248 | <# var field; var index = data.index; #> |
||
| 249 | |||
| 250 | <li class="repeater-row minimized" data-row="{{{ index }}}"> |
||
| 251 | |||
| 252 | <div class="repeater-row-header"> |
||
| 253 | <span class="repeater-row-label"></span> |
||
| 254 | <i class="dashicons dashicons-arrow-down repeater-minimize"></i> |
||
| 255 | </div> |
||
| 256 | <div class="repeater-row-content"> |
||
| 257 | <# _.each( data, function( field, i ) { #> |
||
| 258 | |||
| 259 | <div class="repeater-field repeater-field-{{{ field.type }}} repeater-field-{{ field.id }}"> |
||
| 260 | |||
| 261 | <# if ( 'text' === field.type || 'url' === field.type || 'link' === field.type || 'email' === field.type || 'tel' === field.type || 'date' === field.type || 'number' === field.type ) { #> |
||
| 262 | <# var fieldExtras = ''; #> |
||
| 263 | <# if ( 'link' === field.type ) { #> |
||
| 264 | <# field.type = 'url' #> |
||
| 265 | <# } #> |
||
| 266 | |||
| 267 | <# if ( 'number' === field.type ) { #> |
||
| 268 | <# if ( ! _.isUndefined( field.choices ) && ! _.isUndefined( field.choices.min ) ) { #> |
||
| 269 | <# fieldExtras += ' min="' + field.choices.min + '"'; #> |
||
| 270 | <# } #> |
||
| 271 | <# if ( ! _.isUndefined( field.choices ) && ! _.isUndefined( field.choices.max ) ) { #> |
||
| 272 | <# fieldExtras += ' max="' + field.choices.max + '"'; #> |
||
| 273 | <# } #> |
||
| 274 | <# if ( ! _.isUndefined( field.choices ) && ! _.isUndefined( field.choices.step ) ) { #> |
||
| 275 | <# fieldExtras += ' step="' + field.choices.step + '"'; #> |
||
| 276 | <# } #> |
||
| 277 | <# } #> |
||
| 278 | |||
| 279 | <label> |
||
| 280 | <# if ( field.label ) { #><span class="customize-control-title">{{{ field.label }}}</span><# } #> |
||
| 281 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 282 | <input type="{{field.type}}" name="" value="{{{ field.default }}}" data-field="{{{ field.id }}}"{{ fieldExtras }}> |
||
| 283 | </label> |
||
| 284 | |||
| 285 | <# } else if ( 'number' === field.type ) { #> |
||
| 286 | |||
| 287 | <label> |
||
| 288 | <# if ( field.label ) { #><span class="customize-control-title">{{{ field.label }}}</span><# } #> |
||
| 289 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 290 | <input type="{{ field.type }}" name="" value="{{{ field.default }}}" data-field="{{{ field.id }}}"{{ numberFieldExtras }}> |
||
| 291 | </label> |
||
| 292 | |||
| 293 | <# } else if ( 'hidden' === field.type ) { #> |
||
| 294 | |||
| 295 | <input type="hidden" data-field="{{{ field.id }}}" <# if ( field.default ) { #> value="{{{ field.default }}}" <# } #> /> |
||
| 296 | |||
| 297 | <# } else if ( 'checkbox' === field.type ) { #> |
||
| 298 | |||
| 299 | <label> |
||
| 300 | <input type="checkbox" value="{{{ field.default }}}" data-field="{{{ field.id }}}" <# if ( field.default ) { #> checked="checked" <# } #> /> {{{ field.label }}} |
||
| 301 | <# if ( field.description ) { #>{{{ field.description }}}<# } #> |
||
| 302 | </label> |
||
| 303 | |||
| 304 | <# } else if ( 'select' === field.type ) { #> |
||
| 305 | |||
| 306 | <label> |
||
| 307 | <# if ( field.label ) { #><span class="customize-control-title">{{{ field.label }}}</span><# } #> |
||
| 308 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 309 | <select data-field="{{{ field.id }}}"<# if ( ! _.isUndefined( field.multiple ) && false !== field.multiple ) { #> multiple="multiple" data-multiple="{{ field.multiple }}"<# } #>> |
||
| 310 | <# _.each( field.choices, function( choice, i ) { #> |
||
| 311 | <option value="{{{ i }}}" <# if ( -1 !== jQuery.inArray( i, field.default ) || field.default == i ) { #> selected="selected" <# } #>>{{ choice }}</option> |
||
| 312 | <# }); #> |
||
| 313 | </select> |
||
| 314 | </label> |
||
| 315 | |||
| 316 | <# } else if ( 'dropdown-pages' === field.type ) { #> |
||
| 317 | |||
| 318 | <label> |
||
| 319 | <# if ( field.label ) { #><span class="customize-control-title">{{{ data.label }}}</span><# } #> |
||
| 320 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 321 | <div class="customize-control-content repeater-dropdown-pages">{{{ field.dropdown }}}</div> |
||
| 322 | </label> |
||
| 323 | |||
| 324 | <# } else if ( 'radio' === field.type ) { #> |
||
| 325 | |||
| 326 | <label> |
||
| 327 | <# if ( field.label ) { #><span class="customize-control-title">{{{ field.label }}}</span><# } #> |
||
| 328 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 329 | |||
| 330 | <# _.each( field.choices, function( choice, i ) { #> |
||
| 331 | <label><input type="radio" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> {{ choice }} <br/></label> |
||
| 332 | <# }); #> |
||
| 333 | </label> |
||
| 334 | |||
| 335 | <# } else if ( 'radio-image' === field.type ) { #> |
||
| 336 | |||
| 337 | <label> |
||
| 338 | <# if ( field.label ) { #><span class="customize-control-title">{{{ field.label }}}</span><# } #> |
||
| 339 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 340 | |||
| 341 | <# _.each( field.choices, function( choice, i ) { #> |
||
| 342 | <input type="radio" id="{{{ field.id }}}_{{ index }}_{{{ i }}}" name="{{{ field.id }}}{{ index }}" data-field="{{{ field.id }}}" value="{{{ i }}}" <# if ( field.default == i ) { #> checked="checked" <# } #>> |
||
| 343 | <label for="{{{ field.id }}}_{{ index }}_{{{ i }}}"><img src="{{ choice }}"></label> |
||
| 344 | </input> |
||
| 345 | <# }); #> |
||
| 346 | </label> |
||
| 347 | |||
| 348 | <# } else if ( 'color' === field.type ) { #> |
||
| 349 | |||
| 350 | <label> |
||
| 351 | <# if ( field.label ) { #><span class="customize-control-title">{{{ field.label }}}</span><# } #> |
||
| 352 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 353 | </label> |
||
| 354 | <# var defaultValue = ''; |
||
| 355 | if ( field.default ) { |
||
| 356 | if ( -1 === field.default.indexOf( 'rgba' ) ) { |
||
| 357 | defaultValue = ( '#' !== field.default.substring( 0, 1 ) ) ? '#' + field.default : field.default; |
||
| 358 | defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically. |
||
| 359 | } else { |
||
| 360 | defaultValue = ' data-default-color="' + defaultValue + '" data-alpha="true"'; |
||
| 361 | } |
||
| 362 | } #> |
||
| 363 | <input class="color-picker-hex" type="text" maxlength="7" value="{{{ field.default }}}" data-field="{{{ field.id }}}" {{ defaultValue }} /> |
||
| 364 | |||
| 365 | <# } else if ( 'textarea' === field.type ) { #> |
||
| 366 | |||
| 367 | <# if ( field.label ) { #><span class="customize-control-title">{{{ field.label }}}</span><# } #> |
||
| 368 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 369 | <textarea rows="5" data-field="{{{ field.id }}}">{{ field.default }}</textarea> |
||
| 370 | |||
| 371 | <# } else if ( field.type === 'image' || field.type === 'cropped_image' ) { #> |
||
| 372 | |||
| 373 | <label> |
||
| 374 | <# if ( field.label ) { #><span class="customize-control-title">{{{ field.label }}}</span><# } #> |
||
| 375 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 376 | </label> |
||
| 377 | |||
| 378 | <figure class="kirki-image-attachment" data-placeholder="<?php esc_attr_e( 'No Image Selected', 'kirki' ); ?>" > |
||
| 379 | <# if ( field.default ) { #> |
||
| 380 | <# var defaultImageURL = ( field.default.url ) ? field.default.url : field.default; #> |
||
| 381 | <img src="{{{ defaultImageURL }}}"> |
||
| 382 | <# } else { #> |
||
| 383 | <?php esc_html_e( 'No Image Selected', 'kirki' ); ?> |
||
| 384 | <# } #> |
||
| 385 | </figure> |
||
| 386 | |||
| 387 | <div class="actions"> |
||
| 388 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php esc_html_e( 'Remove', 'kirki' ); ?></button> |
||
| 389 | <button type="button" class="button upload-button" data-label=" <?php esc_attr_e( 'Add Image', 'kirki' ); ?>" data-alt-label="<?php echo esc_attr_e( 'Change Image', 'kirki' ); ?>" > |
||
| 390 | <# if ( field.default ) { #> |
||
| 391 | <?php esc_html_e( 'Change Image', 'kirki' ); ?> |
||
| 392 | <# } else { #> |
||
| 393 | <?php esc_html_e( 'Add Image', 'kirki' ); ?> |
||
| 394 | <# } #> |
||
| 395 | </button> |
||
| 396 | <# if ( field.default.id ) { #> |
||
| 397 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
| 398 | <# } else { #> |
||
| 399 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
| 400 | <# } #> |
||
| 401 | </div> |
||
| 402 | |||
| 403 | <# } else if ( field.type === 'upload' ) { #> |
||
| 404 | |||
| 405 | <label> |
||
| 406 | <# if ( field.label ) { #><span class="customize-control-title">{{{ field.label }}}</span><# } #> |
||
| 407 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 408 | </label> |
||
| 409 | |||
| 410 | <figure class="kirki-file-attachment" data-placeholder="<?php esc_attr_e( 'No File Selected', 'kirki' ); ?>" > |
||
| 411 | <# if ( field.default ) { #> |
||
| 412 | <# var defaultFilename = ( field.default.filename ) ? field.default.filename : field.default; #> |
||
| 413 | <span class="file"><span class="dashicons dashicons-media-default"></span> {{ defaultFilename }}</span> |
||
| 414 | <# } else { #> |
||
| 415 | <?php esc_html_e( 'No File Selected', 'kirki' ); ?> |
||
| 416 | <# } #> |
||
| 417 | </figure> |
||
| 418 | |||
| 419 | <div class="actions"> |
||
| 420 | <button type="button" class="button remove-button<# if ( ! field.default ) { #> hidden<# } #>"><?php esc_html_e( 'Remove', 'kirki' ); ?></button> |
||
| 421 | <button type="button" class="button upload-button" data-label="<?php esc_attr_e( 'Add File', 'kirki' ); ?>" data-alt-label="<?php esc_attr_e( 'Change File', 'kirki' ); ?>"> |
||
| 422 | <# if ( field.default ) { #> |
||
| 423 | <?php esc_html_e( 'Change File', 'kirki' ); ?> |
||
| 424 | <# } else { #> |
||
| 425 | <?php esc_html_e( 'Add File', 'kirki' ); ?> |
||
| 426 | <# } #> |
||
| 427 | </button> |
||
| 428 | <# if ( field.default.id ) { #> |
||
| 429 | <input type="hidden" class="hidden-field" value="{{{ field.default.id }}}" data-field="{{{ field.id }}}" > |
||
| 430 | <# } else { #> |
||
| 431 | <input type="hidden" class="hidden-field" value="{{{ field.default }}}" data-field="{{{ field.id }}}" > |
||
| 432 | <# } #> |
||
| 433 | </div> |
||
| 434 | |||
| 435 | <# } else if ( 'custom' === field.type ) { #> |
||
| 436 | |||
| 437 | <# if ( field.label ) { #><span class="customize-control-title">{{{ field.label }}}</span><# } #> |
||
| 438 | <# if ( field.description ) { #><span class="description customize-control-description">{{{ field.description }}}</span><# } #> |
||
| 439 | <div data-field="{{{ field.id }}}">{{{ field.default }}}</div> |
||
| 440 | |||
| 441 | <# } #> |
||
| 442 | |||
| 443 | </div> |
||
| 444 | <# }); #> |
||
| 445 | <button type="button" class="button-link repeater-row-remove"><?php esc_html_e( 'Remove', 'kirki' ); ?></button> |
||
| 446 | </div> |
||
| 484 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.