Completed
Pull Request — master (#303)
by Sam
04:22
created

ResultListMovies   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 17.19 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 11
loc 64
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getColumnDefinitions() 0 11 1
A getRatingColumn() 0 11 1
A getRuntimeColumn() 11 11 1
A getDateAddedColumn() 0 11 1

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
/**
4
 * ResultList implementation for movies
5
 *
6
 * @author Sam Stenvall <[email protected]>
7
 * @copyright Copyright &copy; Sam Stenvall 2014-
8
 * @license https://www.gnu.org/licenses/gpl.html The GNU General Public License v3.0
9
 */
10
class ResultListMovies extends ResultList
11
{
12
13
	public function getColumnDefinitions()
14
	{
15
		return array(
16
			$this->getLabelColumn(),
17
			$this->getYearColumn(),
18
			$this->getGenreColumn(),
19
			$this->getRatingColumn(),
20
			$this->getRuntimeColumn(),
21
			$this->getDateAddedColumn(),
22
		);
23
	}
24
25
	/**
26
	 * Returns the column definition for the rating column
27
	 * @return array
28
	 */
29
	private function getRatingColumn()
30
	{
31
		return array(
32
			'name'=>'rating',
33
			'header'=>Yii::t('MovieList', 'Rating'),
34
			'value'=>function($data) {
35
				/* @var $data Movie */
36
				echo $data->getRating();
37
			}
38
		);
39
	}
40
41
	/**
42
	 * Returns the column definition for the runtime column
43
	 * @return array
44
	 */
45 View Code Duplication
	private function getRuntimeColumn()
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...
46
	{
47
		return array(
48
			'name'=>'runtime',
49
			'header'=>Yii::t('GenericList', 'Runtime'),
50
			'value'=>function($data) {
51
				/* @var $data Movie */
52
				echo $data->getRuntimeString();
53
			}
54
		);
55
	}
56
57
58
	/**
59
	 * Returns the column definition for the dateadded column
60
	 * @return array
61
	 */
62
	private function getDateAddedColumn()
63
	{
64
		return [
65
			'name'   => 'dateadded',
66
			'header' => Yii::t('MovieList', 'Date added'),
67
			'value'  => function ($data) {
68
				/** @var Movie $data */
69
				echo $data->getDateAdded();
70
			},
71
		];
72
	}
73
}
74