| Conditions | 7 |
| Paths | 9 |
| Total Lines | 64 |
| Code Lines | 29 |
| Lines | 3 |
| Ratio | 4.69 % |
| 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 |
||
| 68 | public function widget( $args, $instance ) { |
||
| 69 | // We never should show more than 1 instance of this. |
||
| 70 | if ( null === self::$instance ) { |
||
| 71 | $instance = wp_parse_args( $instance, array( |
||
| 72 | 'title' => $this->default_title, |
||
| 73 | ) ); |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Filter the layout of the Google Translate Widget. |
||
| 77 | * |
||
| 78 | * 3 different integers are accepted. |
||
| 79 | * 0 for the vertical layout. |
||
| 80 | * 1 for the horizontal layout. |
||
| 81 | * 2 for the dropdown only. |
||
| 82 | * |
||
| 83 | * @see https://translate.google.com/manager/website/ |
||
| 84 | * |
||
| 85 | * @module widgets |
||
| 86 | * |
||
| 87 | * @since 5.5.0 |
||
| 88 | * |
||
| 89 | * @param string $layout layout of the Google Translate Widget. |
||
| 90 | */ |
||
| 91 | $button_layout = apply_filters( 'jetpack_google_translate_widget_layout', 0 ); |
||
| 92 | |||
| 93 | if ( |
||
| 94 | ! is_int( $button_layout ) |
||
| 95 | || 0 > $button_layout |
||
| 96 | || 2 < $button_layout |
||
| 97 | ) { |
||
| 98 | $button_layout = 0; |
||
| 99 | } |
||
| 100 | |||
| 101 | wp_localize_script( |
||
| 102 | 'google-translate-init', |
||
| 103 | '_wp_google_translate_widget', |
||
| 104 | array( |
||
| 105 | 'lang' => get_locale(), |
||
| 106 | 'layout' => intval( $button_layout ), |
||
| 107 | ) |
||
| 108 | ); |
||
| 109 | wp_enqueue_script( 'google-translate-init' ); |
||
| 110 | wp_enqueue_script( 'google-translate' ); |
||
| 111 | |||
| 112 | $title = $instance['title']; |
||
| 113 | |||
| 114 | if ( ! isset( $title ) ) { |
||
| 115 | $title = $this->default_title; |
||
| 116 | } |
||
| 117 | |||
| 118 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
||
| 119 | $title = apply_filters( 'widget_title', $title ); |
||
| 120 | |||
| 121 | echo $args['before_widget']; |
||
| 122 | View Code Duplication | if ( ! empty( $title ) ) { |
|
| 123 | echo $args['before_title'] . esc_html( $title ) . $args['after_title']; |
||
| 124 | } |
||
| 125 | echo '<div id="google_translate_element"></div>'; |
||
| 126 | echo $args['after_widget']; |
||
| 127 | self::$instance = $instance; |
||
| 128 | /** This action is documented in modules/widgets/gravatar-profile.php */ |
||
| 129 | do_action( 'jetpack_stats_extra', 'widget_view', 'google-translate' ); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 181 |
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.