Passed
Push — developer ( 03fcd5...bb4f07 )
by Mariusz
237:41 queued 202:38
created

DetailView::process()   C

Complexity

Conditions 12
Paths 12

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 6.9666
c 0
b 0
f 0
cc 12
nc 12
nop 0

How to fix   Complexity   

Long Method

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:

1
<?php
2
/**
3
 * Base detail view file.
4
 *
5
 * @package View
6
 *
7
 * @copyright YetiForce Sp. z o.o.
8
 * @license   YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Mariusz Krzaczkowski <[email protected]>
10
 * @author    Radosław Skrzypczak <[email protected]>
11
 */
12
13
namespace YF\Modules\Base\View;
14
15
use App\Purifier;
16
use YF\Modules\Base\Model\DetailView as DetailViewModel;
17
use YF\Modules\Base\Model\Field;
18
use YF\Modules\Base\Model\InventoryField;
19
use YF\Modules\Base\Model\Record;
20
21
/**
22
 * Base detail view class.
23
 */
24
class DetailView extends \App\Controller\View
25
{
26
	/** {@inheritdoc} */
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