| Conditions | 16 |
| Paths | 38 |
| Total Lines | 62 |
| 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 |
||
| 44 | function customize_register( $wp_customize ) { |
||
| 45 | |||
| 46 | $wp_customize->add_section( $this->prefix, |
||
| 47 | array( |
||
| 48 | 'title' => esc_html__( 'Related Posts', 'jetpack' ), |
||
| 49 | 'description' => '', |
||
| 50 | 'capability' => 'edit_theme_options', |
||
| 51 | 'priority' => 89, |
||
| 52 | ) |
||
| 53 | ); |
||
| 54 | |||
| 55 | $selective_options = array(); |
||
| 56 | |||
| 57 | foreach ( $this->get_options( $wp_customize ) as $key => $field ) { |
||
| 58 | $control_id = "$this->prefix[$key]"; |
||
| 59 | $selective_options[] = $control_id; |
||
| 60 | $wp_customize->add_setting( $control_id, |
||
| 61 | array( |
||
| 62 | 'default' => isset( $field['default'] ) ? $field['default'] : '', |
||
| 63 | 'type' => isset( $field['setting_type'] ) ? $field['setting_type'] : 'option', |
||
| 64 | 'capability' => isset( $field['capability'] ) ? $field['capability'] : 'edit_theme_options', |
||
| 65 | 'transport' => isset( $field['transport'] ) ? $field['transport'] : 'postMessage', |
||
| 66 | ) |
||
| 67 | ); |
||
| 68 | $control_settings = array( |
||
| 69 | 'label' => isset( $field['label'] ) ? $field['label'] : '', |
||
| 70 | 'description' => isset( $field['description'] ) ? $field['description'] : '', |
||
| 71 | 'settings' => $control_id, |
||
| 72 | 'type' => isset( $field['control_type'] ) ? $field['control_type'] : 'text', |
||
| 73 | 'section' => $this->prefix, |
||
| 74 | 'priority' => 10, |
||
| 75 | 'active_callback' => isset( $field['active_callback'] ) ? $field['active_callback'] : __CLASS__ . '::is_single', |
||
| 76 | ); |
||
| 77 | switch ( $field['control_type'] ) { |
||
| 78 | case 'text': |
||
| 79 | case 'checkbox': |
||
| 80 | default: |
||
| 81 | $wp_customize->add_control( new WP_Customize_Control( $wp_customize, $control_id, $control_settings ) ); |
||
| 82 | break; |
||
| 83 | case 'select': |
||
| 84 | if ( isset( $field['choices'] ) ) { |
||
| 85 | $control_settings['choices'] = $field['choices']; |
||
| 86 | $wp_customize->add_control( new WP_Customize_Control( $wp_customize, $control_id, $control_settings ) ); |
||
| 87 | } |
||
| 88 | break; |
||
| 89 | case 'message': |
||
| 90 | $wp_customize->add_control( new Jetpack_Message_Control( $wp_customize, $control_id, $control_settings ) ); |
||
| 91 | break; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | // If selective refresh is available, implement it. |
||
| 96 | if ( isset( $wp_customize->selective_refresh ) ) { |
||
| 97 | $wp_customize->selective_refresh->add_partial( "$this->prefix", array( |
||
| 98 | 'selector' => '.jp-relatedposts', |
||
| 99 | 'settings' => $selective_options, |
||
| 100 | 'render_callback' => __CLASS__ . '::render_callback', |
||
| 101 | 'container_inclusive' => false, |
||
| 102 | ) ); |
||
| 103 | } |
||
| 104 | |||
| 105 | } |
||
| 106 | |||
| 245 | new Jetpack_Related_Posts_Customize; |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.