Conditions | 11 |
Paths | 10 |
Total Lines | 18 |
Code Lines | 10 |
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 |
||
27 | function add_gutenberg_compatible_body_class( $classes ) { |
||
28 | // if ( ! is_home() && ! is_front_page() ). |
||
29 | if ( is_page() || is_page_template() || is_single() ) |
||
30 | $classes[] = 'gutenberg-compatible-template'; |
||
31 | |||
32 | // Add a class if the page is using the Content and Media block. |
||
33 | $post = get_post(); |
||
34 | if ( function_exists( 'has_blocks' ) && isset( $post->post_content ) && has_blocks( $post->post_content ) && ( ! is_search() ) && ( ! is_archive() ) ) { |
||
35 | $blocks = parse_blocks( $post->post_content ); |
||
36 | |||
37 | if ( 'core/media-text' === $blocks[0]['blockName'] ) { |
||
38 | $classes[] = 'has-block-media-text'; |
||
39 | } |
||
40 | if ( 'core/cover' === $blocks[0]['blockName'] ) { |
||
41 | $classes[] = 'has-block-cover'; |
||
42 | } |
||
43 | } |
||
44 | return $classes; |
||
45 | } |
||
67 |