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

ApproveHandler::index()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 18
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 18
loc 18
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
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 ApproveHandler 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 = 'approve';
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-tick';
22
23
    protected $destructive = false;
24
25
    protected $label = 'Approve';
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->markApproved();
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