Conditions | 13 |
Paths | 7 |
Total Lines | 41 |
Lines | 3 |
Ratio | 7.32 % |
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 |
||
87 | public static function gutenblock_render( $attr ) { |
||
88 | global $wordads; |
||
89 | |||
90 | /** This filter is already documented in modules/wordads/wordads.php `insert_ad()` */ |
||
91 | if ( |
||
92 | empty( $wordads ) |
||
93 | || empty( $wordads->params ) |
||
94 | || is_feed() |
||
95 | || apply_filters( 'wordads_inpost_disable', false ) |
||
96 | ) { |
||
97 | return ''; |
||
98 | } |
||
99 | |||
100 | if ( ! empty( $attr['hideMobile'] ) && $wordads->params->is_mobile() ) { |
||
101 | return ''; |
||
102 | } |
||
103 | |||
104 | if ( ! self::is_wpcom() && $wordads->option( 'wordads_house' ) ) { |
||
105 | return $wordads->get_ad( 'inline', 'house' ); |
||
106 | } |
||
107 | |||
108 | // section_id is mostly depricated at this point, but it helps us (devs) keep track of which ads end up where |
||
109 | // 6 is to keep track of gutenblock ads. |
||
110 | $section_id = $wordads->params->blog_id . '6'; |
||
111 | $align = 'center'; |
||
112 | View Code Duplication | if ( isset( $attr['align'] ) && in_array( $attr['align'], array( 'left', 'center', 'right' ), true ) ) { |
|
113 | $align = $attr['align']; |
||
114 | } |
||
115 | $align = 'align' . $align; |
||
116 | |||
117 | $ad_tag_ids = $wordads->get_ad_tags(); |
||
118 | $format = 'mrec'; |
||
119 | if ( isset( $attr['format'] ) && in_array( $attr['format'], array_keys( $ad_tag_ids ), true ) ) { |
||
120 | $format = $attr['format']; |
||
121 | } |
||
122 | |||
123 | $height = $ad_tag_ids[ $format ]['height']; |
||
124 | $width = $ad_tag_ids[ $format ]['width']; |
||
125 | $snippet = $wordads->get_ad_snippet( $section_id, $height, $width, 'gutenberg', $wordads->get_solo_unit_css() ); |
||
126 | return $wordads->get_ad_div( 'inline', $snippet, array( $align ) ); |
||
127 | } |
||
128 | } |
||
132 |