Total Complexity | 47 |
Total Lines | 296 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
Complex classes like AppRecordFrame 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 AppRecordFrame, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
38 | class AppRecordFrame extends AppUiObject |
||
39 | { |
||
40 | /** |
||
41 | * @var WidgetSection[] |
||
42 | */ |
||
43 | protected $sections = array(); |
||
44 | |||
45 | /** |
||
46 | * @var AppRecord |
||
47 | */ |
||
48 | protected $record = null; |
||
49 | |||
50 | /** |
||
51 | * @var AppRecordSet |
||
52 | */ |
||
53 | protected $recordSet = null; |
||
54 | |||
55 | |||
56 | /** |
||
57 | * @param Func_App $app |
||
58 | * @param AppRecord $record |
||
59 | * @param string $id |
||
60 | * @param WidgetLayout $layout |
||
61 | */ |
||
62 | public function __construct(Func_App $app, AppRecord $record, $id = null, WidgetLayout $layout = null) |
||
63 | { |
||
64 | parent::__construct($app); |
||
65 | $this->setRecord($record); |
||
66 | $W = bab_Widgets(); |
||
67 | $this->setInheritedItem($W->Frame($id, $layout)); |
||
68 | } |
||
69 | |||
70 | |||
71 | /** |
||
72 | * Creates section in the editor. |
||
73 | * If a section with the same header text (title) was already |
||
74 | * created it is replaced by an empty section. |
||
75 | * |
||
76 | * @param string $headerText |
||
77 | * @return WidgetSection |
||
78 | */ |
||
79 | protected function addSection($id, $headerText, $layout = null) |
||
80 | { |
||
81 | $W = bab_Widgets(); |
||
82 | if (!isset($layout)) { |
||
83 | $layout = $W->VBoxLayout()->setVerticalSpacing(0.6, 'em'); |
||
84 | } |
||
85 | $this->sections[$id] = $W->Section( |
||
86 | $headerText, |
||
87 | $layout |
||
88 | )->setFoldable(true); |
||
89 | |||
90 | return $this->sections[$id]; |
||
91 | } |
||
92 | |||
93 | |||
94 | /** |
||
95 | * Retrieves a section in the editor. |
||
96 | * |
||
97 | * @param string $headerText |
||
98 | * @return WidgetSection |
||
99 | */ |
||
100 | protected function getSection($id) |
||
106 | } |
||
107 | |||
108 | |||
109 | /** |
||
110 | * @param string $textLabel |
||
111 | * @param WidgetDisplayableInterface|string $value |
||
112 | * @param AppCustomSection $section |
||
113 | * @return WidgetDisplayableInterface |
||
114 | */ |
||
115 | public function labelledWidget($textLabel, $value, AppCustomSection $section = null) |
||
166 | } |
||
167 | } |
||
168 | } |
||
169 | |||
170 | |||
171 | /** |
||
172 | * |
||
173 | * @param string $textLabel |
||
174 | * @param mixed $displayedValue |
||
175 | * @param mixed $value |
||
176 | * @param AppCustomSection $section |
||
177 | * @return WidgetDisplayableInterface|null |
||
178 | */ |
||
179 | public function labelledWidgetOptional($textLabel, $displayedValue, $value = null, AppCustomSection $section = null) |
||
180 | { |
||
181 | if (!isset($value)) { |
||
182 | $value = $displayedValue; |
||
183 | } |
||
184 | if (!isset($value) || is_numeric($value) && $value == 0 || is_string($value) && trim($value) == '' || ($value instanceof WidgetLayout && count($value->getItems()) <= 0)) { |
||
185 | return null; |
||
186 | } |
||
187 | $labelledWidget = $this->labelledWidget($textLabel, $displayedValue, $section); |
||
188 | return $labelledWidget; |
||
189 | } |
||
190 | |||
191 | |||
192 | /** |
||
193 | * |
||
194 | * @param ORMField $field |
||
195 | * @param ORMRecord $record |
||
196 | * @param string $fieldName |
||
197 | * @return mixed |
||
198 | */ |
||
199 | protected function fieldOutput($field, $record, $fieldName) |
||
200 | { |
||
201 | if ($field instanceof ORMCurrencyField) { |
||
202 | $App = $this->App(); |
||
203 | $value = $App->shortFormatWithUnit($this->record->$fieldName, $App->translate('_euro_')); |
||
204 | } else { |
||
205 | $value = $field->output($this->record->$fieldName); |
||
206 | } |
||
207 | if (is_array($value)) { |
||
208 | $value = implode(', ', $value); |
||
209 | } |
||
210 | return $value; |
||
211 | } |
||
212 | |||
213 | |||
214 | /** |
||
215 | * |
||
216 | * @param AppCustomSection $customSection |
||
217 | * @param array $displayField |
||
218 | * @param string $textLabel |
||
219 | * @param WidgetDisplayableInterface|string $value |
||
220 | * @return WidgetDisplayableInterface |
||
221 | */ |
||
222 | protected function getValueItem(AppCustomSection $customSection, $displayField, $textLabel, $value) |
||
223 | { |
||
224 | if ($value instanceof WidgetDisplayableInterface) { |
||
225 | return $value; |
||
226 | } |
||
227 | $W = bab_Widgets(); |
||
228 | $parameters = $displayField['parameters']; |
||
229 | if (isset($parameters['type'])) { |
||
230 | if ($parameters['type'] === 'title1') { |
||
231 | $item = $W->Title($value, 1); |
||
232 | } elseif ($parameters['type'] === 'title2') { |
||
233 | $item = $W->Title($value, 2); |
||
234 | } elseif ($parameters['type'] === 'title3') { |
||
235 | $item = $W->Title($value, 3); |
||
236 | } else { |
||
237 | $item = $W->Label($value); |
||
238 | } |
||
239 | } else { |
||
240 | $item = $W->Label($value); |
||
241 | } |
||
242 | $labelledWidgetOptional = $this->labelledWidget( //Optional( |
||
243 | $textLabel, |
||
244 | $item, |
||
245 | // $value, |
||
246 | $customSection |
||
247 | ); |
||
248 | |||
249 | if (isset($labelledWidgetOptional)) { |
||
250 | $labelledWidgetOptional->addClass($displayField['fieldname']); |
||
251 | } |
||
252 | |||
253 | return $labelledWidgetOptional; |
||
254 | } |
||
255 | |||
256 | |||
257 | /** |
||
258 | * @param string $view |
||
259 | */ |
||
260 | protected function addSections($view) |
||
334 | } |
||
335 | } |
||
336 | } |
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