| Conditions | 12 |
| Paths | 512 |
| Total Lines | 56 |
| 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 |
||
| 32 | public static function render_form( $instance ) { |
||
| 33 | if ( empty( $instance ) || ! is_array( $instance ) ) { |
||
| 34 | $instance = array(); |
||
| 35 | } |
||
| 36 | |||
| 37 | if ( empty( $instance['show_subscribers_total'] ) || 'false' === $instance['show_subscribers_total'] ) { |
||
| 38 | $instance['show_subscribers_total'] = false; |
||
| 39 | } else { |
||
| 40 | $instance['show_subscribers_total'] = true; |
||
| 41 | } |
||
| 42 | |||
| 43 | $show_only_email_and_button = isset( $instance['show_only_email_and_button'] ) ? $instance['show_only_email_and_button'] : false; |
||
| 44 | $submit_button_text = isset( $instance['submit_button_text'] ) ? $instance['submit_button_text'] : ''; |
||
| 45 | |||
| 46 | /* |
||
| 47 | * Build up a string |
||
| 48 | * with the submit button's classes and styles |
||
| 49 | * and set it on the instance |
||
| 50 | */ |
||
| 51 | $submit_button_classes = isset( $instance['submit_button_classes'] ) ? $instance['submit_button_classes'] : ''; |
||
| 52 | $submit_button_styles = ''; |
||
| 53 | if ( isset( $instance['custom_background_button_color'] ) ) { |
||
| 54 | $submit_button_styles .= 'background-color: ' . $instance['custom_background_button_color'] . '; '; |
||
| 55 | } |
||
| 56 | if ( isset( $instance['custom_text_button_color'] ) ) { |
||
| 57 | $submit_button_styles .= 'color: ' . $instance['custom_text_button_color'] . ';'; |
||
| 58 | } |
||
| 59 | |||
| 60 | $instance = shortcode_atts( |
||
| 61 | Widget::defaults(), |
||
|
|
|||
| 62 | $instance, |
||
| 63 | 'jetpack_subscription_form' |
||
| 64 | ); |
||
| 65 | |||
| 66 | // These must come after the call to shortcode_atts(). |
||
| 67 | $instance['submit_button_text'] = $submit_button_text; |
||
| 68 | $instance['show_only_email_and_button'] = $show_only_email_and_button; |
||
| 69 | if ( ! empty( $submit_button_classes ) ) { |
||
| 70 | $instance['submit_button_classes'] = $submit_button_classes; |
||
| 71 | } |
||
| 72 | if ( ! empty( $submit_button_styles ) ) { |
||
| 73 | $instance['submit_button_styles'] = $submit_button_styles; |
||
| 74 | } |
||
| 75 | |||
| 76 | $args = array( |
||
| 77 | 'before_widget' => '<div class="jetpack_subscription_widget">', |
||
| 78 | ); |
||
| 79 | |||
| 80 | ob_start(); |
||
| 81 | |||
| 82 | the_widget( Helpers::widget_classname(), $instance, $args ); |
||
| 83 | |||
| 84 | $output = ob_get_clean(); |
||
| 85 | |||
| 86 | return $output; |
||
| 87 | } |
||
| 88 | } |
||
| 89 |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.