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

CommentsGridFieldBulkAction_Handlers   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 68 %

Coupling/Cohesion

Components 0
Dependencies 3
Metric Value
wmc 4
lcom 0
cbo 3
dl 34
loc 50
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A spam() 17 17 2
A approve() 17 17 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
/**
4
 * @package comments
5
 */
6
class CommentsGridFieldBulkAction extends GridFieldBulkActionHandler {
7
8
}
9
10
/**
11
 * A {@link GridFieldBulkActionHandler} for bulk marking comments as spam
12
 *
13
 * @package comments
14
 */
15
class CommentsGridFieldBulkAction_Handlers extends CommentsGridFieldBulkAction {
16
17
	private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
18
		'spam',
19
		'approve',
20
	);
21
22
	private static $url_handlers = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
23
		'spam' => 'spam',
24
		'approve' => 'approve',
25
	);
26
27
28 View Code Duplication
	public function spam(SS_HTTPRequest $request) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
29
		$ids = array();
30
31
		foreach($this->getRecords() as $record) {
32
			array_push($ids, $record->ID);
33
			$record->markSpam();
34
		}
35
36
		$response = new SS_HTTPResponse(Convert::raw2json(array(
37
			'done' => true,
38
			'records' => $ids
39
		)));
40
41
		$response->addHeader('Content-Type', 'text/json');
42
43
		return $response;
44
	}
45
46
47 View Code Duplication
	public function approve(SS_HTTPRequest $request) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
48
		$ids = array();
49
50
		foreach($this->getRecords() as $record) {
51
			array_push($ids, $record->ID);
52
			$record->markApproved();
53
		}
54
55
		$response = new SS_HTTPResponse(Convert::raw2json(array(
56
			'done' => true,
57
			'records' => $ids
58
		)));
59
60
		$response->addHeader('Content-Type', 'text/json');
61
62
		return $response;
63
	}
64
}