Conditions | 21 |
Paths | 129 |
Total Lines | 62 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
192 | public function loadData(): void |
||
193 | { |
||
194 | if (empty($this->data)) { |
||
195 | return; |
||
196 | } |
||
197 | if ($recordId = $this->request->getInteger('record')) { |
||
198 | $recordModel = \Vtiger_Record_Model::getInstanceById($recordId, $this->moduleName); |
||
199 | $this->response['recordModel'] = $recordModel; |
||
200 | $fieldsModel = $recordModel->getModule()->getFields(); |
||
201 | } else { |
||
202 | $fieldsModel = \Vtiger_Module_Model::getInstance($this->moduleName)->getFields(); |
||
203 | } |
||
204 | $additional = $fieldsData = $skip = []; |
||
205 | $rows = isset($this->data[0]) ? $this->data : [$this->data]; |
||
206 | foreach ($rows as $key => &$row) { |
||
207 | $dataCounter[$key] = 0; |
||
208 | if (empty($row)) { |
||
209 | continue; |
||
210 | } |
||
211 | foreach ($this->formFieldsToRecordMap[$this->moduleName] as $apiKey => $fieldName) { |
||
212 | if (empty($fieldsModel[$fieldName]) || !$fieldsModel[$fieldName]->isActiveField()) { |
||
213 | if (isset($row[$apiKey]) && '' !== $row[$apiKey] && null !== $row[$apiKey]) { |
||
214 | $skip[$fieldName]['data'][$key] = $row[$apiKey]; |
||
215 | if (isset($fieldsModel[$fieldName]) && empty($skip[$fieldName]['label'])) { |
||
216 | $skip[$fieldName]['label'] = \App\Language::translate($fieldsModel[$fieldName]->getFieldLabel(), $this->moduleName); |
||
217 | } else { |
||
218 | $skip[$fieldName]['label'] = $fieldName; |
||
219 | } |
||
220 | } |
||
221 | unset($row[$apiKey]); |
||
222 | continue; |
||
223 | } |
||
224 | $value = ''; |
||
225 | if (isset($row[$apiKey])) { |
||
226 | $value = trim($row[$apiKey]); |
||
227 | unset($row[$apiKey]); |
||
228 | } |
||
229 | if ('' === $value && isset($fieldsData[$fieldName]['data'][$key])) { |
||
230 | continue; |
||
231 | } |
||
232 | if ($value) { |
||
233 | ++$dataCounter[$key]; |
||
|
|||
234 | } |
||
235 | $fieldModel = $fieldsModel[$fieldName]; |
||
236 | $fieldsData[$fieldName]['label'] = \App\Language::translate($fieldModel->getFieldLabel(), $this->moduleName); |
||
237 | $fieldsData[$fieldName]['data'][$key] = [ |
||
238 | 'raw' => $value, |
||
239 | 'edit' => $fieldModel->getEditViewDisplayValue($value), |
||
240 | 'display' => $fieldModel->getDisplayValue($value, false, false, false, 40), |
||
241 | ]; |
||
242 | } |
||
243 | foreach ($row as $name => $value) { |
||
244 | if ('' !== $value && null !== $value) { |
||
245 | $additional[$name][$key] = $value; |
||
246 | } |
||
247 | } |
||
248 | } |
||
249 | $this->response['fields'] = $fieldsData; |
||
250 | $this->response['skip'] = $skip; |
||
251 | $this->response['keys'] = array_keys($rows); |
||
252 | $this->response['additional'] = $additional; |
||
253 | $this->response['dataCounter'] = $dataCounter; |
||
254 | } |
||
288 |