Completed
Pull Request — master (#232)
by Robbie
01:50
created

SpamHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 3
dl 37
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A index() 18 18 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
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
4
5
use Colymba\BulkManager\BulkAction\Handler;
6
use SilverStripe\Core\Convert;
7
use SilverStripe\Control\HTTPRequest;
8
use SilverStripe\Control\HTTPResponse;
9
10
/**
11
 * A {@link GridFieldBulkActionHandler} for bulk marking comments as spam
12
 */
13 View Code Duplication
class SpamHandler extends Handler
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    private static $allowed_actions = ['index'];
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...
Unused Code introduced by
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
17
    private static $url_segment = 'spam';
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...
Unused Code introduced by
The property $url_segment is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
18
19
    protected $xhr = true;
20
21
    protected $buttonClasses = 'font-icon-cross-mark';
22
23
    protected $destructive = false;
24
25
    protected $label = 'Spam';
26
27
    /**
28
     * @param  HTTPRequest $request
29
     * @return HTTPResponse
30
     */
31
    public function index(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...
32
    {
33
        $ids = array();
34
35
        foreach ($this->getRecords() as $record) {
36
            array_push($ids, $record->ID);
37
            $record->markSpam();
38
        }
39
40
        $response = new HTTPResponse(Convert::raw2json(array(
41
            'done' => true,
42
            'records' => $ids
43
        )));
44
45
        $response->addHeader('Content-Type', 'text/json');
46
47
        return $response;
48
    }
49
}
50