Conditions | 11 |
Paths | 10 |
Total Lines | 44 |
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 |
||
48 | public function details() |
||
49 | { |
||
50 | $moduleName = $this->request->getModule(); |
||
51 | $record = $this->request->getByType('record', Purifier::INTEGER); |
||
52 | $recordModel = Record::getInstanceById($moduleName, $record, ['x-header-fields' => 1]); |
||
53 | $moduleStructure = $recordModel->getModuleModel()->getFieldsFromApi(); |
||
54 | $inventoryFields = $fieldsForm = $fields = []; |
||
55 | foreach ($moduleStructure['fields'] as $field) { |
||
56 | $fieldInstance = Field::getInstance($moduleName, $field); |
||
57 | if ($recordModel->has($field['name'])) { |
||
58 | $fieldInstance->setDisplayValue($recordModel->get($field['name'])); |
||
59 | } |
||
60 | if ($field['isViewable']) { |
||
61 | $fieldsForm[$field['blockId']][] = $fieldInstance; |
||
62 | } |
||
63 | $fields[$field['name']] = $fieldInstance; |
||
64 | } |
||
65 | if (!empty($moduleStructure['inventory'])) { |
||
66 | $columns = \Conf\Inventory::$columnsByModule[$moduleName] ?? \Conf\Inventory::$columns ?? []; |
||
67 | $columnsIsActive = !empty($columns); |
||
68 | foreach ($moduleStructure['inventory'] as $fieldType => $fieldsInventory) { |
||
69 | if (1 === $fieldType) { |
||
70 | foreach ($fieldsInventory as $field) { |
||
71 | if ($field['isVisibleInDetail'] && (!$columnsIsActive || \in_array($field['columnname'], $columns))) { |
||
72 | $inventoryFields[] = InventoryField::getInstance($moduleName, $field); |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 | } |
||
78 | $detailViewModel = DetailViewModel::getInstance($moduleName); |
||
79 | $detailViewModel->setRecordModel($recordModel); |
||
80 | $this->viewer->assign('BREADCRUMB_TITLE', $recordModel->getName()); |
||
81 | $this->viewer->assign('RECORD', $recordModel); |
||
82 | $this->viewer->assign('FIELDS', $fields); |
||
83 | $this->viewer->assign('FIELDS_FORM', $fieldsForm); |
||
84 | $this->viewer->assign('BLOCKS', $moduleStructure['blocks']); |
||
85 | $this->viewer->assign('INVENTORY_FIELDS', $inventoryFields); |
||
86 | $this->viewer->assign('SHOW_INVENTORY_RIGHT_COLUMN', \Conf\Inventory::$showInventoryRightColumn); |
||
87 | $this->viewer->assign('SUMMARY_INVENTORY', $recordModel->getInventorySummary()); |
||
88 | $this->viewer->assign('DETAIL_LINKS', $detailViewModel->getLinksHeader()); |
||
89 | $this->viewer->assign('FIELDS_HEADER', $recordModel->getCustomData()['headerFields'] ?? []); |
||
90 | $this->viewer->view('Detail/DetailView.tpl', $moduleName); |
||
91 | } |
||
92 | |||
103 |