Conditions | 5 |
Paths | 4 |
Total Lines | 139 |
Code Lines | 77 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
40 | public static function render_callback( $attrs, $content, $block, $elements ) { |
||
41 | $post_heading_level = $attrs['postTitle']['decoration']['font']['font']['desktop']['value']['headingLevel']; |
||
42 | $posts_per_page = $attrs['postItems']['innerContent']['desktop']['value']['postsNumber']; |
||
43 | |||
44 | $background_component = ElementComponents::component( |
||
45 | [ |
||
46 | 'attrs' => $attrs['module']['decoration'] ?? [], |
||
47 | 'id' => $block->parsed_block['id'], |
||
48 | |||
49 | // FE only. |
||
50 | 'orderIndex' => $block->parsed_block['orderIndex'], |
||
51 | 'storeInstance' => $block->parsed_block['storeInstance'], |
||
52 | ] |
||
53 | ); |
||
54 | |||
55 | $posts = get_posts( |
||
56 | [ |
||
57 | 'post_type' => 'post', |
||
58 | 'posts_per_page' => $posts_per_page, |
||
59 | ] |
||
60 | ); |
||
61 | |||
62 | $post_items = ''; |
||
63 | |||
64 | if ( is_array( $posts ) && count( $posts ) ) { |
||
65 | foreach ( $posts as $post ) { |
||
66 | |||
67 | // Post title with link. |
||
68 | $post_title = HTMLUtility::render( |
||
69 | [ |
||
70 | 'tag' => 'a', |
||
71 | 'attributes' => [ |
||
72 | 'href' => get_permalink( $post ), |
||
73 | ], |
||
74 | 'childrenSanitizer' => 'esc_html', |
||
75 | 'children' => get_the_title( $post ), |
||
76 | ] |
||
77 | ); |
||
78 | |||
79 | // Post title container. |
||
80 | $post_title_container = HTMLUtility::render( |
||
81 | [ |
||
82 | 'tag' => $post_heading_level, |
||
83 | 'attributes' => [ |
||
84 | 'class' => 'example_dynamic_module__post-item-title', |
||
85 | ], |
||
86 | 'childrenSanitizer' => 'et_core_esc_previously', |
||
87 | 'children' => $post_title, |
||
88 | ] |
||
89 | ); |
||
90 | |||
91 | // Post content. |
||
92 | $post_content = HTMLUtility::render( |
||
93 | [ |
||
94 | 'tag' => 'div', |
||
95 | 'attributes' => [ |
||
96 | 'class' => 'example_dynamic_module__post-item-content', |
||
97 | ], |
||
98 | 'childrenSanitizer' => 'et_core_esc_previously', |
||
99 | 'children' => get_the_excerpt( $post ), |
||
100 | ] |
||
101 | ); |
||
102 | |||
103 | // Post item. |
||
104 | $post_items .= HTMLUtility::render( |
||
105 | [ |
||
106 | 'tag' => 'div', |
||
107 | 'attributes' => [ |
||
108 | 'class' => 'example_dynamic_module__post-item', |
||
109 | ], |
||
110 | 'childrenSanitizer' => 'et_core_esc_previously', |
||
111 | 'children' => $post_title_container . $post_content, |
||
112 | ] |
||
113 | ); |
||
114 | } |
||
115 | } |
||
116 | |||
117 | // Title. |
||
118 | $title = $elements->render( |
||
119 | [ |
||
120 | 'attrName' => 'title', |
||
121 | ] |
||
122 | ); |
||
123 | |||
124 | // Posts container. |
||
125 | if ( ! empty( $post_items ) ) { |
||
126 | $posts_container = HTMLUtility::render( |
||
127 | [ |
||
128 | 'tag' => 'div', |
||
129 | 'attributes' => [ |
||
130 | 'class' => 'example_dynamic_module__post-items', |
||
131 | ], |
||
132 | 'childrenSanitizer' => 'et_core_esc_previously', |
||
133 | 'children' => $post_items, |
||
134 | ] |
||
135 | ); |
||
136 | } else { |
||
137 | $posts_container = HTMLUtility::render( |
||
138 | [ |
||
139 | 'tag' => 'div', |
||
140 | 'childrenSanitizer' => 'esc_html', |
||
141 | 'children' => __( 'No post found.', 'd5-extension-example-modules' ), |
||
142 | ] |
||
143 | ); |
||
144 | } |
||
145 | |||
146 | $parent = BlockParserStore::get_parent( $block->parsed_block['id'], $block->parsed_block['storeInstance'] ); |
||
147 | $parent_attrs = $parent->attrs ?? []; |
||
148 | |||
149 | return Module::render( |
||
150 | [ |
||
151 | // FE only. |
||
152 | 'orderIndex' => $block->parsed_block['orderIndex'], |
||
153 | 'storeInstance' => $block->parsed_block['storeInstance'], |
||
154 | |||
155 | // VB equivalent. |
||
156 | 'id' => $block->parsed_block['id'], |
||
157 | 'name' => $block->block_type->name, |
||
158 | 'moduleCategory' => $block->block_type->category, |
||
159 | 'attrs' => $attrs, |
||
160 | 'elements' => $elements, |
||
161 | 'classnamesFunction' => [ self::class, 'module_classnames' ], |
||
162 | 'stylesComponent' => [ self::class, 'module_styles' ], |
||
163 | 'scriptDataComponent' => [ self::class, 'module_script_data' ], |
||
164 | 'parentAttrs' => $parent_attrs, |
||
165 | 'parentId' => $parent->id ?? '', |
||
166 | 'parentName' => $parent->blockName ?? '', |
||
167 | 'children' => [ |
||
168 | $background_component, |
||
169 | HTMLUtility::render( |
||
170 | [ |
||
171 | 'tag' => 'div', |
||
172 | 'attributes' => [ |
||
173 | 'class' => 'example_dynamic_module__inner', |
||
174 | ], |
||
175 | 'childrenSanitizer' => 'et_core_esc_previously', |
||
176 | 'children' => [ |
||
177 | $title, |
||
178 | $posts_container, |
||
179 | ], |
||
187 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths