Passed
Push — master ( d7fd6a...9124ff )
by Robbie
11:58
created

DatedUpdatePage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 5.17 %

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
dl 3
loc 58
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldLabels() 0 6 1
A getCMSFields() 0 21 1
A populateDefaults() 2 5 3

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
class DatedUpdatePage extends Page {
0 ignored issues
show
Bug introduced by
The type Page was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
3
4
	// Meant as an abstract base class.
5
	private static $hide_ancestor = 'DatedUpdatePage';
0 ignored issues
show
introduced by
The private property $hide_ancestor is not used, and could be removed.
Loading history...
6
7
	private static $singular_name = 'Dated Update Page';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
8
9
	private static $plural_name = 'Dated Update Pages';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
10
11
	private static $defaults = array(
0 ignored issues
show
introduced by
The private property $defaults is not used, and could be removed.
Loading history...
12
		'ShowInMenus' => false
13
	);
14
15
	private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
16
		'Abstract' => 'Text',
17
		'Date' => 'Datetime'
18
	);
19
20
	/**
21
	 * Add the default for the Date being the current day.
22
	 */
23
	public function populateDefaults() {
24
		parent::populateDefaults();
25
26 View Code Duplication
		if(!isset($this->Date) || $this->Date === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
27
			$this->Date = SS_Datetime::now()->Format('Y-m-d 09:00:00');
0 ignored issues
show
Bug Best Practice introduced by
The property Date does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28
		}
29
	}
30
31
	public function fieldLabels($includerelations = true) {
32
		$labels = parent::fieldLabels($includerelations);
33
		$labels['Date'] = _t('DateUpdatePage.DateLabel', 'Date');
34
		$labels['Abstract'] = _t('DateUpdatePage.AbstractTextFieldLabel', 'Abstract');
35
36
		return $labels;
37
	}
38
39
	public function getCMSFields() {
40
		$this->beforeUpdateCMSFields(function (FieldList $fields) {
41
			$fields->addFieldToTab(
42
				'Root.Main',
43
				$dateTimeField = DatetimeField::create('Date', $this->fieldLabel('Date')),
44
				'Content'
45
			);
46
			$dateTimeField->getDateField()->setConfig('showcalendar', true);
47
48
			$fields->addfieldToTab(
49
				'Root.Main',
50
				$abstractField = TextareaField::create('Abstract', $this->fieldLabel('Abstract')),
51
				'Content'
52
			);
53
			$abstractField->setAttribute('maxlength', '160');
54
			$abstractField->setRightTitle(
55
				_t('DateUpdatePage.AbstractDesc','The abstract is used as a summary on the listing pages. It is limited to 160 characters.')
56
			);
57
			$abstractField->setRows(6);
58
		});
59
		return parent::getCMSFields();
60
	}
61
}
62
63
class DatedUpdatePage_Controller extends Page_Controller {
0 ignored issues
show
Bug introduced by
The type Page_Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
64
}
65