| Conditions | 12 |
| Paths | 12 |
| Total Lines | 45 |
| 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 |
||
| 27 | public function process() |
||
| 28 | { |
||
| 29 | $moduleName = $this->request->getModule(); |
||
| 30 | $record = $this->request->getByType('record', Purifier::INTEGER); |
||
| 31 | $recordModel = Record::getInstanceById($moduleName, $record); |
||
| 32 | $moduleStructure = $recordModel->getModuleModel()->getFieldsFromApi(); |
||
| 33 | $inventoryFields = $fields = $headerFields = []; |
||
| 34 | foreach ($moduleStructure['fields'] as $field) { |
||
| 35 | if ($field['isViewable']) { |
||
| 36 | $fieldInstance = Field::getInstance($moduleName, $field); |
||
| 37 | if ($recordModel->has($field['name'])) { |
||
| 38 | $fieldInstance->setDisplayValue($recordModel->get($field['name'])); |
||
| 39 | } |
||
| 40 | $fields[$field['blockId']][] = $fieldInstance; |
||
| 41 | if (!empty($field['header_field'])) { |
||
| 42 | $headerFields[$field['header_field']['type']][$field['name']] = $fieldInstance; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 | if (!empty($moduleStructure['inventory'])) { |
||
| 47 | $columns = \Conf\Inventory::$columnsByModule[$moduleName] ?? \Conf\Inventory::$columns ?? []; |
||
| 48 | $columnsIsActive = !empty($columns); |
||
| 49 | foreach ($moduleStructure['inventory'] as $fieldType => $fieldsInventory) { |
||
| 50 | if (1 === $fieldType) { |
||
| 51 | foreach ($fieldsInventory as $field) { |
||
| 52 | if ($field['isVisibleInDetail'] && (!$columnsIsActive || \in_array($field['columnname'], $columns))) { |
||
| 53 | $inventoryFields[] = InventoryField::getInstance($moduleName, $field); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | } |
||
| 59 | $detailViewModel = DetailViewModel::getInstance($moduleName); |
||
| 60 | $detailViewModel->setRecordModel($recordModel); |
||
| 61 | $this->viewer->assign('BREADCRUMB_TITLE', $recordModel->getName()); |
||
| 62 | $this->viewer->assign('RECORD', $recordModel); |
||
| 63 | $this->viewer->assign('FIELDS', $fields); |
||
| 64 | $this->viewer->assign('BLOCKS', $moduleStructure['blocks']); |
||
| 65 | $this->viewer->assign('INVENTORY_FIELDS', $inventoryFields); |
||
| 66 | $this->viewer->assign('SHOW_INVENTORY_RIGHT_COLUMN', \Conf\Inventory::$showInventoryRightColumn); |
||
| 67 | $this->viewer->assign('SUMMARY_INVENTORY', $recordModel->getInventorySummary()); |
||
| 68 | $this->viewer->assign('DETAIL_LINKS', $detailViewModel->getLinksHeader()); |
||
| 69 | $this->viewer->assign('FIELDS_HEADER', $headerFields); |
||
| 70 | $this->viewer->view('Detail/DetailView.tpl', $moduleName); |
||
| 71 | } |
||
| 72 | } |
||
| 73 |