Conditions | 12 |
Paths | 7 |
Total Lines | 36 |
Lines | 3 |
Ratio | 8.33 % |
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 //phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
75 | public static function gutenblock_render( $attr ) { |
||
76 | global $wordads; |
||
77 | |||
78 | /** This filter is already documented in modules/wordads/wordads.php `insert_ad()` */ |
||
79 | if ( empty( $wordads ) || is_feed() || apply_filters( 'wordads_inpost_disable', false ) ) { |
||
80 | return ''; |
||
81 | } |
||
82 | |||
83 | if ( ! empty( $attr['hideMobile'] ) && $wordads->params->is_mobile() ) { |
||
84 | return ''; |
||
85 | } |
||
86 | |||
87 | if ( ! self::is_wpcom() && $wordads->option( 'wordads_house' ) ) { |
||
88 | return $wordads->get_ad( 'inline', 'house' ); |
||
89 | } |
||
90 | |||
91 | // section_id is mostly depricated at this point, but it helps us (devs) keep track of which ads end up where |
||
92 | // 6 is to keep track of gutenblock ads. |
||
93 | $section_id = $wordads->params->blog_id . '6'; |
||
94 | $align = 'center'; |
||
95 | View Code Duplication | if ( isset( $attr['align'] ) && in_array( $attr['align'], array( 'left', 'center', 'right' ), true ) ) { |
|
96 | $align = $attr['align']; |
||
97 | } |
||
98 | $align = 'align' . $align; |
||
99 | |||
100 | $ad_tag_ids = $wordads->get_ad_tags(); |
||
101 | $format = 'mrec'; |
||
102 | if ( isset( $attr['format'] ) && in_array( $attr['format'], array_keys( $ad_tag_ids ), true ) ) { |
||
103 | $format = $attr['format']; |
||
104 | } |
||
105 | |||
106 | $height = $ad_tag_ids[ $format ]['height']; |
||
107 | $width = $ad_tag_ids[ $format ]['width']; |
||
108 | $snippet = $wordads->get_ad_snippet( $section_id, $height, $width, 'inline', $wordads->get_solo_unit_css() ); |
||
109 | return $wordads->get_ad_div( 'inline', $snippet, array( $align ) ); |
||
110 | } |
||
111 | } |
||
122 |