Test Failed
Push — develop ( db5b9c...b55dd4 )
by Paul
17:52
created

ModuleStylesTrait::module_styles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 121
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 52
c 1
b 0
f 0
dl 0
loc 121
rs 9.0472
cc 1
nc 1
nop 1

How to fix   Long Method   

Long Method

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:

1
<?php
2
/**
3
 * ChildModule::module_styles().
4
 *
5
 * @package Builder\Packages\ModuleLibrary
6
 * @since ??
7
 */
8
9
namespace MEE\Modules\ChildModule\ChildModuleTrait;
10
11
if ( ! defined( 'ABSPATH' ) ) {
12
	die( 'Direct access forbidden.' );
13
}
14
15
use ET\Builder\FrontEnd\Module\Style;
0 ignored issues
show
Bug introduced by
The type ET\Builder\FrontEnd\Module\Style was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use ET\Builder\Packages\Module\Options\Text\TextStyle;
0 ignored issues
show
Bug introduced by
The type ET\Builder\Packages\Module\Options\Text\TextStyle was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use ET\Builder\Packages\Module\Options\Css\CssStyle;
0 ignored issues
show
Bug introduced by
The type ET\Builder\Packages\Module\Options\Css\CssStyle was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use ET\Builder\Packages\Module\Layout\Components\StyleCommon\CommonStyle;
0 ignored issues
show
Bug introduced by
The type ET\Builder\Packages\Modu...StyleCommon\CommonStyle was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use ET\Builder\Packages\ModuleLibrary\ModuleRegistration;
0 ignored issues
show
Bug introduced by
The type ET\Builder\Packages\Modu...rary\ModuleRegistration was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use MEE\Modules\ChildModule\ChildModule;
21
22
trait ModuleStylesTrait {
23
24
	use CustomCssTrait;
25
	use StyleDeclarationTrait;
26
27
	/**
28
	 * Child Module's style components.
29
	 *
30
	 * This function is equivalent of JS function ModuleStyles located in
31
	 * src/components/child-module/styles.tsx.
32
	 *
33
	 * @param array $args {
34
	 *     An array of arguments.
35
	 *
36
	 * @type string $id Module ID. In VB, the ID of module is UUIDV4. In FE, the ID is order index.
37
	 * @type string $name Module name.
38
	 * @type string $attrs Module attributes.
39
	 * @type string $parentAttrs Parent attrs.
40
	 * @type string $orderClass Selector class name.
41
	 * @type string $parentOrderClass Parent selector class name.
42
	 * @type string $wrapperOrderClass Wrapper selector class name.
43
	 * @type string $settings Custom settings.
44
	 * @type string $state Attributes state.
45
	 * @type string $mode Style mode.
46
	 * @type ModuleElements $elements ModuleElements instance.
47
	 * }
48
	 * @since ??
49
	 */
50
	public static function module_styles( $args ) {
51
		$attrs        = $args['attrs'] ?? [];
52
		$order_class  = $args['orderClass'];
53
		$elements     = $args['elements'];
54
		$settings     = $args['settings'] ?? [];
55
		$parent_attrs = $args['parentAttrs'] ?? [];
56
57
		$parent_default_attributes = ModuleRegistration::get_default_attrs( 'example/parent-module' );
58
		$parent_attrs_with_default = array_replace_recursive( $parent_default_attributes, $parent_attrs );
59
60
		$content_container_selector = "{$order_class} .example_child_module__content-container";
61
62
		Style::add(
63
			[
64
				'id'            => $args['id'],
65
				'name'          => $args['name'],
66
				'orderIndex'    => $args['orderIndex'],
67
				'storeInstance' => $args['storeInstance'],
68
				'styles'        => [
69
					// Module.
70
					$elements->style(
71
						[
72
							'attrName'   => 'module',
73
							'styleProps' => [
74
								'disabledOn'     => [
75
									'disabledModuleVisibility' => $settings['disabledModuleVisibility'] ?? null,
76
								],
77
								'advancedStyles' => [
78
									[
79
										'componentName' => 'divi/text',
80
										'props'         => [
81
											'selector' => $content_container_selector,
82
											'attr'     => $attrs['module']['advanced']['text'] ?? [],
83
										]
84
									]
85
								]
86
							],
87
						]
88
					),
89
90
					// Title.
91
					$elements->style(
92
						[
93
							'attrName' => 'title',
94
						]
95
					),
96
97
					// Content.
98
					$elements->style(
99
						[
100
							'attrName' => 'content',
101
						]
102
					),
103
104
					// Icon.
105
					$elements->style(
106
						[
107
							'attrName'   => 'icon',
108
							'styleProps' => [
109
								'advancedStyles' => [
110
									[
111
										'componentName' => 'divi/common',
112
										'props'         => [
113
											'attr'                => $attrs['icon']['innerContent'] ?? $parent_attrs_with_default['icon']['innerContent'] ?? [],
114
											'declarationFunction' => [ChildModule::class, 'icon_font_declaration'],
115
										]
116
									],
117
									[
118
										'componentName' => 'divi/common',
119
										'props'         => [
120
											'attr'     => $attrs['icon']['advanced']['color'] ?? $parent_attrs_with_default['icon']['advanced']['color'] ?? [],
121
											'property' => 'color',
122
										]
123
									],
124
									[
125
										'componentName' => 'divi/common',
126
										'props'         => [
127
											'attr'     => $attrs['icon']['advanced']['size'] ?? $parent_attrs_with_default['icon']['advanced']['size'] ?? [],
128
											'property' => 'font-size',
129
										]
130
									],
131
								]
132
							]
133
						]
134
					),
135
136
					/*
137
					 * We need to add CssStyle at the very bottom of other
138
					 * components so that custom css can override module styles
139
					 * till we find a more elegant solution.
140
					 */
141
					CssStyle::style(
142
						[
143
							'selector'  => $args['orderClass'],
144
							'attr'      => $attrs['css'] ?? [],
145
							'cssFields' => self::custom_css(),
146
						]
147
					),
148
149
					// ATTENTION: The code is intentionally added and commented in FE only as an example of expected value format.
150
					// If you have custom style processing, the style output should be passed as an `array` of style declarations
151
					// to the `styles` property of the `Style::add` method. For example:
152
					// [
153
					// 	[
154
					// 		'atRules'     => false,
155
					// 		'selector'    => $icon_selector,
156
					// 		'declaration' => 'color: red;'
157
					// 	],
158
					// 	[
159
					// 		'atRules'     => '@media only screen and (max-width: 767px)',
160
					// 		'selector'    => $icon_selector,
161
					// 		'declaration' => 'color: green;'
162
					// 	],
163
					// ],
164
165
					// The code below is an example of how to use the `CssStyle::style` method to generate CSS style.
166
					CssStyle::style(
167
						[
168
							'selector'  => $args['orderClass'],
169
							'attr'      => $attrs['css'] ?? [],
170
							'cssFields' => self::custom_css(),
171
						]
172
					),
173
				],
174
			]
175
		);
176
	}
177
178
}
179