Completed
Push — master ( b1bf62...c2fee6 )
by Damian
01:51
created

code/admin/CommentAdmin.php (1 issue)

mismatching argument types.

Documentation Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Comment administration system within the CMS
5
 *
6
 * @package comments
7
 */
8
class CommentAdmin extends LeftAndMain implements PermissionProvider {
9
10
	private static $url_segment = 'comments';
11
12
	private static $url_rule = '/$Action';
13
14
	private static $menu_title = 'Comments';
15
16
	private static $allowed_actions = array(
17
		'approvedmarked',
18
		'deleteall',
19
		'deletemarked',
20
		'hammarked',
21
		'showtable',
22
		'spammarked',
23
		'EditForm',
24
		'unmoderated'
25
	);
26
27
	public function providePermissions() {
28
		return array(
29
			"CMS_ACCESS_CommentAdmin" => array(
30
				'name' => _t('CommentAdmin.ADMIN_PERMISSION', "Access to 'Comments' section"),
31
				'category' => _t('Permission.CMS_ACCESS_CATEGORY', 'CMS Access')
32
			)
33
		);
34
	}
35
36
	/**
37
	 * @return Form
38
	 */
39
	public function getEditForm($id = null, $fields = null) {
40
		if(!$id) $id = $this->currentPageID();
41
42
		$form = parent::getEditForm($id);
43
		$record = $this->getRecord($id);
44
45
		if($record && !$record->canView()) {
46
			return Security::permissionFailure($this);
47
		}
48
49
		$newComments = Comment::get()->filter('Moderated', 0);
50
51
		$newGrid = new CommentsGridField(
52
			'NewComments',
53
			_t('CommentsAdmin.NewComments', 'New'),
54
			$newComments,
55
			CommentsGridFieldConfig::create()
56
		);
57
58
		$approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0);
59
60
		$approvedGrid = new CommentsGridField(
61
			'ApprovedComments',
62
			_t('CommentsAdmin.ApprovedComments', 'Approved'),
63
			$approvedComments,
64
			CommentsGridFieldConfig::create()
65
		);
66
67
		$spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1);
68
69
		$spamGrid = new CommentsGridField(
70
			'SpamComments',
71
			_t('CommentsAdmin.SpamComments', 'Spam'),
72
			$spamComments,
73
			CommentsGridFieldConfig::create()
74
		);
75
76
		$newCount = '(' . count($newComments) . ')';
77
		$approvedCount = '(' . count($approvedComments) . ')';
78
		$spamCount = '(' . count($spamComments) . ')';
79
80
		$fields = new FieldList(
81
			$root = new TabSet(
82
				'Root',
83
				new Tab('NewComments', _t('CommentAdmin.NewComments', 'New') . ' ' . $newCount,
84
					$newGrid
85
				),
86
				new Tab('ApprovedComments', _t('CommentAdmin.ApprovedComments', 'Approved') . ' ' . $approvedCount,
87
					$approvedGrid
88
				),
89
				new Tab('SpamComments', _t('CommentAdmin.SpamComments', 'Spam') . ' ' . $spamCount,
90
					$spamGrid
91
				)
92
			)
93
		);
94
95
		$root->setTemplate('CMSTabSet');
96
97
		$actions = new FieldList();
98
99
		$form = new Form(
100
			$this,
101
			'EditForm',
102
			$fields,
103
			$actions
104
		);
105
106
		$form->addExtraClass('cms-edit-form');
107
		$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
0 ignored issues
show
$this->getTemplatesWithSuffix('_EditForm') is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
108
109
		if($form->Fields()->hasTabset()) {
110
			$form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
111
			$form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses());
112
		}
113
114
		$this->extend('updateEditForm', $form);
115
116
		return $form;
117
	}
118
}
119