Total Complexity | 54 |
Total Lines | 345 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like AppCustomSection often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AppCustomSection, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
50 | class AppCustomSection extends AppTraceableRecord |
||
51 | { |
||
52 | |||
53 | const FIELDS_LAYOUT_VERTICAL_LABEL = 'verticalLabel'; |
||
54 | |||
55 | const FIELDS_LAYOUT_HORIZONTAL_LABEL = 'horizontalLabel'; |
||
56 | |||
57 | const FIELDS_LAYOUT_WIDE_HORIZONTAL_LABEL = 'wideHorizontalLabel'; |
||
58 | |||
59 | const FIELDS_LAYOUT_VERY_WIDE_HORIZONTAL_LABEL = 'veryWideHorizontalLabel'; |
||
60 | |||
61 | const FIELDS_LAYOUT_NO_LABEL = 'noLabel'; |
||
62 | |||
63 | /** |
||
64 | * @return string[] |
||
65 | */ |
||
66 | public static function getFieldsLayouts() |
||
67 | { |
||
68 | $App = app_App(); |
||
69 | static $fieldsLayouts = null; |
||
70 | |||
71 | if(! isset($fieldsLayouts)){ |
||
72 | $fieldsLayouts = array( |
||
73 | self::FIELDS_LAYOUT_VERTICAL_LABEL => $App->translate('Vertical label'), |
||
74 | self::FIELDS_LAYOUT_HORIZONTAL_LABEL => $App->translate('Horizontal label'), |
||
75 | self::FIELDS_LAYOUT_WIDE_HORIZONTAL_LABEL => $App->translate('Horizontal label (wide)'), |
||
76 | self::FIELDS_LAYOUT_VERY_WIDE_HORIZONTAL_LABEL => $App->translate('Horizontal label (very wide)'), |
||
77 | self::FIELDS_LAYOUT_NO_LABEL => $App->translate('No label') |
||
78 | ); |
||
79 | } |
||
80 | return $fieldsLayouts; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return string[] |
||
85 | */ |
||
86 | public function getRawFields() |
||
87 | { |
||
88 | if(empty($this->fields)){ |
||
89 | return array(); |
||
90 | } |
||
91 | return explode(',', $this->fields); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Return an array containing the fields in the section and their associated parameters. |
||
96 | * [ |
||
97 | * [ |
||
98 | * 'fieldname' => the_field_name, |
||
99 | * 'parameters => [ |
||
100 | * 'type' => the_field_type, |
||
101 | * 'label' => the_field_label, |
||
102 | * 'classname' => the field_classname, |
||
103 | * ... |
||
104 | * ] |
||
105 | * ], |
||
106 | * ... |
||
107 | * ] |
||
108 | * |
||
109 | * @return string[][] |
||
110 | */ |
||
111 | public function getFields() |
||
112 | { |
||
113 | if(empty($this->fields)){ |
||
114 | return array(); |
||
115 | } |
||
116 | $fields = json_decode($this->fields, true); |
||
117 | |||
118 | if(json_last_error() === JSON_ERROR_NONE){ |
||
119 | if(bab_charset::getIso() != bab_charset::UTF_8){ |
||
120 | $fields = app_utf8Decode($fields); |
||
121 | } |
||
122 | return $fields; |
||
123 | } |
||
124 | |||
125 | $fields = array(); |
||
126 | $rawFields = $this->getRawFields(); |
||
127 | foreach ($rawFields as $rawField){ |
||
128 | if(empty($rawField)){ |
||
129 | continue; |
||
130 | } |
||
131 | $params = array(); |
||
132 | |||
133 | if(strpos($rawField, ':') === false){ |
||
134 | $fieldName = $rawField; |
||
135 | } |
||
136 | else{ |
||
137 | list ($fieldName, $parameters) = explode(':', $rawField); |
||
138 | $parameters = explode(';', $parameters); |
||
139 | foreach ($parameters as $parameter){ |
||
140 | list ($key, $value) = explode('=', $parameter); |
||
141 | $params[$key] = $value; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | $fields[$fieldName] = array( |
||
146 | 'block' => '', |
||
147 | 'fieldname' => $fieldName, |
||
148 | 'parameters' => $params |
||
149 | ); |
||
150 | } |
||
151 | return $fields; |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Return an array containing the description of the specified field in the section and its associated parameters or |
||
156 | * null if the field is not present in the section. |
||
157 | * [ |
||
158 | * 'fieldname' => the_field_name, |
||
159 | * 'parameters => [ |
||
160 | * 'type' => the_field_type, |
||
161 | * 'label' => the_field_label, |
||
162 | * 'classname' => the field_classname, |
||
163 | * ... |
||
164 | * ] |
||
165 | * ], |
||
166 | * |
||
167 | * @param string $searchedFieldName |
||
168 | * @return NULL|array[] |
||
169 | */ |
||
170 | public function getField($searchedFieldName) |
||
171 | { |
||
172 | if(empty($this->fields)){ |
||
173 | return null; |
||
174 | } |
||
175 | |||
176 | $fields = $this->getFields(); |
||
177 | return isset($fields[$searchedFieldName]) ? $fields[$searchedFieldName] : null; |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Appends the field to the list of contained fields. |
||
182 | * |
||
183 | * @param string $fieldName |
||
184 | * @param array $parameters |
||
185 | */ |
||
186 | public function addField($fieldName, $parameters = null) |
||
187 | { |
||
188 | $fields = $this->getFields(); |
||
189 | if(! isset($parameters)){ |
||
190 | $fields[$fieldName] = array( |
||
191 | 'block' => '' |
||
192 | ); |
||
193 | $parameters = array(); |
||
194 | } |
||
195 | $fields[$fieldName]['fieldname'] = $fieldName; |
||
196 | $fields[$fieldName]['parameters'] = $parameters; |
||
197 | if(bab_charset::getIso() != bab_charset::UTF_8){ |
||
198 | $fields = app_utf8Encode($fields); |
||
199 | } |
||
200 | $this->fields = json_encode($fields); |
||
201 | return $this; |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * @param string $removedFieldName |
||
206 | */ |
||
207 | public function removeField($removedFieldName) |
||
208 | { |
||
209 | $fields = $this->getFields(); |
||
210 | unset($fields[$removedFieldName]); |
||
211 | if(bab_charset::getIso() != bab_charset::UTF_8){ |
||
212 | $fields = app_utf8Encode($fields); |
||
213 | } |
||
214 | $this->fields = json_encode($fields); |
||
215 | return $this; |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * Update the field, or create it if it does not exist |
||
220 | * |
||
221 | * @param string $updatedFieldName |
||
222 | * @param array $parameters |
||
223 | * @return self |
||
224 | */ |
||
225 | public function updateField($updatedFieldName, $parameters = null) |
||
226 | { |
||
227 | $isFieldsGroup = false; |
||
228 | $fields = $this->getFields(); |
||
229 | if(strpos($updatedFieldName, '_fieldsGroup') !== false){ |
||
230 | $isFieldsGroup = true; |
||
231 | list (, $groupPos) = explode('_fieldsGroup', $updatedFieldName); |
||
232 | if(! isset($groupPos) || empty($groupPos)){ |
||
233 | $groupPos = 0; |
||
234 | } |
||
235 | } |
||
236 | if(! isset($fields[$updatedFieldName])){ |
||
237 | if($isFieldsGroup){ |
||
238 | while (isset($fields[$updatedFieldName . $groupPos])){ |
||
239 | $groupPos ++; |
||
240 | } |
||
241 | $updatedFieldName .= $groupPos; |
||
242 | } |
||
243 | $this->addField($updatedFieldName, $parameters); |
||
244 | return $this; |
||
245 | } |
||
246 | if(! isset($parameters)){ |
||
247 | $fields[$updatedFieldName] = array( |
||
248 | 'block' => '' |
||
249 | ); |
||
250 | $parameters = array(); |
||
251 | } |
||
252 | $fields[$updatedFieldName]['fieldname'] = $updatedFieldName; |
||
253 | $fields[$updatedFieldName]['parameters'] = $parameters; |
||
254 | if(bab_charset::getIso() != bab_charset::UTF_8){ |
||
255 | $fields = app_utf8Encode($fields); |
||
256 | } |
||
257 | $this->fields = json_encode($fields); |
||
258 | return $this; |
||
259 | } |
||
260 | |||
261 | public function addFieldToGroup($fieldGroupName, $fieldName, $parameters = null) |
||
262 | { |
||
263 | $fields = $this->getFields(); |
||
264 | if(! isset($fields[$fieldGroupName])){ |
||
265 | return $this; |
||
266 | } |
||
267 | $groupFields = isset($fields[$fieldGroupName]['fields']) ? $fields[$fieldGroupName]['fields'] : array(); |
||
268 | if(! isset($parameters)){ |
||
269 | $groupFields[$fieldName] = array( |
||
270 | 'block' => '' |
||
271 | ); |
||
272 | $parameters = array(); |
||
273 | } |
||
274 | $groupFields[$fieldName]['fieldname'] = $fieldName; |
||
275 | $groupFields[$fieldName]['parameters'] = $parameters; |
||
276 | $fields[$fieldGroupName]['fields'] = $groupFields; |
||
277 | if(bab_charset::getIso() != bab_charset::UTF_8){ |
||
278 | $fields = app_utf8Encode($fields); |
||
279 | } |
||
280 | $this->fields = json_encode($fields); |
||
281 | return $this; |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * @param string $removedFieldName |
||
286 | */ |
||
287 | public function removeFieldFromGroup($fieldGroupName, $removedFieldName) |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * Update the field, or create it if it does not exist |
||
300 | * |
||
301 | * @param string $updatedFieldName |
||
302 | * @param array $parameters |
||
303 | * @return self |
||
304 | */ |
||
305 | public function updateFieldGroup($fieldGroupName, $updatedFieldName, $parameters = null) |
||
331 | } |
||
332 | |||
333 | /** |
||
334 | * @param AppRecord $record |
||
335 | * |
||
336 | * @return bool |
||
337 | */ |
||
338 | public function isVisibleForRecord(AppRecord $record) |
||
395 | } |
||
396 | } |
||
397 |
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