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 |
||
75 | } |
||
76 | // Make the block available. Just in case it wasn't registed before. |
||
77 | Jetpack_Gutenberg::set_extension_available( self::BLOCK_NAME ); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Renders the WordAds block. |
||
82 | * |
||
83 | * @param array $attr Block attributes. |
||
84 | * |
||
85 | * @return string Block HTML. |
||
86 | */ |
||
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 | |||
132 |