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 |
||
89 | public function widget( $args, $instance ) { |
||
90 | // We never should show more than 1 instance of this. |
||
91 | if ( null === self::$instance ) { |
||
92 | $instance = wp_parse_args( $instance, array( |
||
93 | 'title' => $this->default_title, |
||
94 | ) ); |
||
95 | |||
96 | /** |
||
97 | * Filter the layout of the Google Translate Widget. |
||
98 | * |
||
99 | * 3 different integers are accepted. |
||
100 | * 0 for the vertical layout. |
||
101 | * 1 for the horizontal layout. |
||
102 | * 2 for the dropdown only. |
||
103 | * |
||
104 | * @see https://translate.google.com/manager/website/ |
||
105 | * |
||
106 | * @module widgets |
||
107 | * |
||
108 | * @since 5.5.0 |
||
109 | * |
||
110 | * @param string $layout layout of the Google Translate Widget. |
||
111 | */ |
||
112 | $button_layout = apply_filters( 'jetpack_google_translate_widget_layout', 0 ); |
||
113 | |||
114 | if ( |
||
115 | ! is_int( $button_layout ) |
||
116 | || 0 > $button_layout |
||
117 | || 2 < $button_layout |
||
118 | ) { |
||
119 | $button_layout = 0; |
||
120 | } |
||
121 | |||
122 | wp_localize_script( |
||
123 | 'google-translate-init', |
||
124 | '_wp_google_translate_widget', |
||
125 | array( |
||
126 | 'lang' => get_locale(), |
||
127 | 'layout' => intval( $button_layout ), |
||
128 | ) |
||
129 | ); |
||
130 | wp_enqueue_script( 'google-translate-init' ); |
||
131 | wp_enqueue_script( 'google-translate' ); |
||
132 | |||
133 | $title = $instance['title']; |
||
134 | |||
135 | if ( ! isset( $title ) ) { |
||
136 | $title = $this->default_title; |
||
137 | } |
||
138 | |||
139 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
||
140 | $title = apply_filters( 'widget_title', $title ); |
||
141 | |||
142 | echo $args['before_widget']; |
||
143 | View Code Duplication | if ( ! empty( $title ) ) { |
|
144 | echo $args['before_title'] . esc_html( $title ) . $args['after_title']; |
||
145 | } |
||
146 | echo '<div id="google_translate_element"></div>'; |
||
147 | echo $args['after_widget']; |
||
148 | self::$instance = $instance; |
||
149 | /** This action is documented in modules/widgets/gravatar-profile.php */ |
||
150 | do_action( 'jetpack_stats_extra', 'widget_view', 'google-translate' ); |
||
151 | } |
||
152 | } |
||
153 | |||
202 |
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.