Passed
Push — developer ( a79ea2...2ba598 )
by Mariusz
229:56 queued 195:01
created

ListView   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 22.58 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 7
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 11 1
A getListViewModel() 7 7 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * Records list 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
/**
16
 * Records list view class.
17
 */
18
class ListView extends \App\Controller\View
19
{
20
	/** @var \YF\Modules\Base\Model\ListView List view model. */
21
	protected $listViewModel;
22
23
	/** {@inheritdoc} */
24
	public function process()
25
	{
26
		$this->getListViewModel()->loadRecordsList();
27
		$moduleName = $this->request->getModule();
28
		$this->viewer->assign('HEADERS', $this->listViewModel->getHeaders());
29
		$this->viewer->assign('RECORDS', $this->listViewModel->getRecordsListModel());
30
		$this->viewer->assign('COUNT', $this->listViewModel->getCount());
31
		$this->viewer->assign('PAGE_NUMBER', 11);
32
		$this->viewer->assign('LIST_VIEW_MODEL', $this->listViewModel);
33
		$this->viewer->view('List/ListView.tpl', $moduleName);
34
	}
35
36
	/**
37
	 * Get list view model.
38
	 *
39
	 * @return \YF\Modules\Base\Model\ListView
40
	 */
41 View Code Duplication
	protected function getListViewModel(): \YF\Modules\Base\Model\ListView
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
	{
43
		if (empty($this->listViewModel)) {
44
			$this->listViewModel = \YF\Modules\Base\Model\ListView::getInstance($this->moduleName, $this->request->getAction());
0 ignored issues
show
Documentation Bug introduced by
It seems like \YF\Modules\Base\Model\L...->request->getAction()) of type object<self> is incompatible with the declared type object<YF\Modules\Base\Model\ListView> of property $listViewModel.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
45
		}
46
		return $this->listViewModel;
47
	}
48
}
49