Conditions | 1 |
Paths | 1 |
Total Lines | 98 |
Code Lines | 55 |
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 |
||
36 | public static function render_callback( $attrs, $content, $block, $elements ) { |
||
37 | // Image. |
||
38 | $image_src = $attrs['image']['innerContent']['desktop']['value']['src'] ?? ''; |
||
39 | $image_alt = $attrs['image']['innerContent']['desktop']['value']['alt'] ?? ''; |
||
40 | $image = HTMLUtility::render( |
||
41 | [ |
||
42 | 'tag' => 'img', |
||
43 | 'attributes' => [ |
||
44 | 'src' => $image_src, |
||
45 | 'alt' => $image_alt, |
||
46 | ], |
||
47 | 'attributesSanitizers' => [ |
||
48 | 'src' => function ( $value ) { |
||
49 | $protocols = array_merge( wp_allowed_protocols(), [ 'data' ] ); // Need to add `data` protocol for default image. |
||
50 | return esc_url( $value, $protocols ); |
||
51 | }, |
||
52 | ], |
||
53 | ] |
||
54 | ); |
||
55 | |||
56 | // Image container. |
||
57 | $image_container = HTMLUtility::render( |
||
58 | [ |
||
59 | 'tag' => 'div', |
||
60 | 'attributes' => [ |
||
61 | 'class' => 'example_static_module__image', |
||
62 | ], |
||
63 | 'childrenSanitizer' => 'et_core_esc_previously', |
||
64 | 'children' => $image, |
||
65 | ] |
||
66 | ); |
||
67 | |||
68 | // Title. |
||
69 | $title = $elements->render( |
||
70 | [ |
||
71 | 'attrName' => 'title', |
||
72 | ] |
||
73 | ); |
||
74 | |||
75 | // Content. |
||
76 | $content = $elements->render( |
||
77 | [ |
||
78 | 'attrName' => 'content', |
||
79 | ] |
||
80 | ); |
||
81 | |||
82 | // Content container. |
||
83 | $content_container = HTMLUtility::render( |
||
84 | [ |
||
85 | 'tag' => 'div', |
||
86 | 'attributes' => [ |
||
87 | 'class' => 'example_static_module__content-container', |
||
88 | ], |
||
89 | 'childrenSanitizer' => 'et_core_esc_previously', |
||
90 | 'children' => $title . $content, |
||
91 | ] |
||
92 | ); |
||
93 | |||
94 | $parent = BlockParserStore::get_parent( $block->parsed_block['id'], $block->parsed_block['storeInstance'] ); |
||
95 | $parent_attrs = $parent->attrs ?? []; |
||
96 | |||
97 | return Module::render( |
||
98 | [ |
||
99 | // FE only. |
||
100 | 'orderIndex' => $block->parsed_block['orderIndex'], |
||
101 | 'storeInstance' => $block->parsed_block['storeInstance'], |
||
102 | |||
103 | // VB equivalent. |
||
104 | 'attrs' => $attrs, |
||
105 | 'elements' => $elements, |
||
106 | 'id' => $block->parsed_block['id'], |
||
107 | 'name' => $block->block_type->name, |
||
108 | 'moduleCategory' => $block->block_type->category, |
||
109 | 'classnamesFunction' => [ StaticModule::class, 'module_classnames' ], |
||
110 | 'stylesComponent' => [ StaticModule::class, 'module_styles' ], |
||
111 | 'scriptDataComponent' => [ StaticModule::class, 'module_script_data' ], |
||
112 | 'parentAttrs' => $parent_attrs, |
||
113 | 'parentId' => $parent->id ?? '', |
||
114 | 'parentName' => $parent->blockName ?? '', |
||
115 | 'children' => [ |
||
116 | ElementComponents::component( |
||
117 | [ |
||
118 | 'attrs' => $attrs['module']['decoration'] ?? [], |
||
119 | 'id' => $block->parsed_block['id'], |
||
120 | |||
121 | // FE only. |
||
122 | 'orderIndex' => $block->parsed_block['orderIndex'], |
||
123 | 'storeInstance' => $block->parsed_block['storeInstance'], |
||
124 | ] |
||
125 | ), |
||
126 | HTMLUtility::render( |
||
127 | [ |
||
128 | 'tag' => 'div', |
||
129 | 'attributes' => [ |
||
130 | 'class' => 'example_static_module__inner', |
||
131 | ], |
||
132 | 'childrenSanitizer' => 'et_core_esc_previously', |
||
133 | 'children' => $image_container . $content_container, |
||
134 | ] |
||
141 |
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