Conditions | 1 |
Paths | 1 |
Total Lines | 118 |
Code Lines | 4 |
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 |
||
161 | static public function jetpack_shortcode_tweet_gutenberg_script() { |
||
162 | ?> |
||
163 | // <script> |
||
164 | ( function( wp ) { |
||
165 | wp.blocks.registerBlockType( 'jetpack/tweet', { |
||
166 | title: wp.i18n.__( 'Tweet', 'jetpack' ), |
||
167 | icon: 'twitter', |
||
168 | category: 'layout', |
||
169 | |||
170 | attributes : { |
||
171 | tweet : function ( node ) { |
||
172 | var shortcode = wp.shortcode.next( 'tweet', node.innerText ); |
||
173 | if ( shortcode.attrs.named.tweet ) { |
||
174 | return shortcode.attrs.named.tweet; |
||
175 | } |
||
176 | if ( shortcode.attrs.numeric[0] ) { |
||
177 | return shortcode.attrs.numeric[0]; |
||
178 | } |
||
179 | return null; |
||
180 | }, |
||
181 | align : function ( node ) { |
||
182 | var shortcode = wp.shortcode.next( 'tweet', node.innerText ); |
||
183 | if ( shortcode.attrs.named.align ) { |
||
184 | return shortcode.attrs.named.align; |
||
185 | } |
||
186 | return 'none'; |
||
187 | }, |
||
188 | width : function ( node ) { |
||
189 | var shortcode = wp.shortcode.next( 'tweet', node.innerText ); |
||
190 | if ( shortcode.attrs.named.width ) { |
||
191 | return shortcode.attrs.named.width; |
||
192 | } |
||
193 | return ''; |
||
194 | }, |
||
195 | lang : function ( node ) { |
||
196 | var shortcode = wp.shortcode.next( 'tweet', node.innerText ); |
||
197 | if ( shortcode.attrs.named.lang ) { |
||
198 | return shortcode.attrs.named.lang; |
||
199 | } |
||
200 | return 'en'; |
||
201 | }, |
||
202 | hide_thread : function ( node ) { |
||
203 | var shortcode = wp.shortcode.next( 'tweet', node.innerText ); |
||
204 | if ( shortcode.attrs.named.hide_thread ) { |
||
205 | return shortcode.attrs.named.hide_thread; |
||
206 | } |
||
207 | return 'false'; |
||
208 | }, |
||
209 | hide_media : function ( node ) { |
||
210 | var shortcode = wp.shortcode.next( 'tweet', node.innerText ); |
||
211 | if ( shortcode.attrs.named.hide_media ) { |
||
212 | return shortcode.attrs.named.hide_media; |
||
213 | } |
||
214 | return 'false'; |
||
215 | } |
||
216 | }, |
||
217 | |||
218 | edit : function( props ) { |
||
219 | return wp.element.createElement( |
||
220 | 'input', |
||
221 | { |
||
222 | name : 'tweet', |
||
223 | type : 'url', |
||
224 | value : props.attributes.tweet, |
||
225 | onChange: function( event ) { |
||
226 | props.setAttributes({ |
||
227 | tweet: event.target.value |
||
228 | }); |
||
229 | } |
||
230 | }, |
||
231 | null |
||
232 | ); |
||
233 | }, |
||
234 | |||
235 | save : function( props ) { |
||
236 | var args = { |
||
237 | tag : 'tweet', |
||
238 | attrs : { |
||
239 | named : {}, |
||
240 | numeric : [ |
||
241 | props.attributes.tweet |
||
242 | ] |
||
243 | } |
||
244 | }; |
||
245 | |||
246 | // Populate optional attributes. |
||
247 | if ( props.attributes.align && props.attributes.align !== 'none' ) { |
||
248 | args.attrs.named.align = props.attributes.align; |
||
249 | } |
||
250 | if ( props.attributes.width && props.attributes.width !== '' ) { |
||
251 | args.attrs.named.width = props.attributes.width; |
||
252 | } |
||
253 | if ( props.attributes.lang && props.attributes.lang !== 'en' ) { |
||
254 | args.attrs.named.lang = props.attributes.lang; |
||
255 | } |
||
256 | if ( props.attributes.hide_thread && props.attributes.hide_thread !== 'none' ) { |
||
257 | args.attrs.named.hide_thread = props.attributes.hide_thread; |
||
258 | } |
||
259 | if ( props.attributes.hide_media && props.attributes.hide_media !== 'none' ) { |
||
260 | args.attrs.named.hide_media = props.attributes.hide_media; |
||
261 | } |
||
262 | |||
263 | if ( props.className ) { |
||
264 | return wp.element.createElement( |
||
265 | 'div', |
||
266 | { className : props.className }, |
||
267 | wp.shortcode.string( args ) |
||
268 | ); |
||
269 | } |
||
270 | |||
271 | return wp.shortcode.string( args ); |
||
272 | } |
||
273 | |||
274 | } ); |
||
275 | } )( window.wp ); |
||
276 | // </script> |
||
277 | <?php |
||
278 | } |
||
279 | |||
281 |
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.