Completed
Push — master ( 438529...cc46cc )
by
unknown
10s
created

Handler::approve()   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
dl 18
loc 18
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
3
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
4
5
use Colymba\BulkManager\BulkAction\Handler as GridFieldBulkActionHandler;
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
 * @deprecated 3.1..4.0 Abstract handlers are removed, please use concrete Spam or Approve handlers
14
 */
15
class Handler extends GridFieldBulkActionHandler
16
{
17
    private static $allowed_actions = array(
0 ignored issues
show
Unused Code introduced by Will Rossiter
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...
Comprehensibility introduced by Robbie Averill
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
Unused Code introduced by Will Rossiter
The property $url_handlers 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...
Comprehensibility introduced by Robbie Averill
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
     * @param  HTTPRequest $request
29
     * @return HTTPResponse
30
     */
31 View Code Duplication
    public function spam(HTTPRequest $request)
0 ignored issues
show
Unused Code introduced by Robbie Averill
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 Robbie Averill
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...
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
    /**
51
     * @param  HTTPRequest $request
52
     * @return HTTPResponse
53
     */
54 View Code Duplication
    public function approve(HTTPRequest $request)
0 ignored issues
show
Unused Code introduced by Robbie Averill
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 Robbie Averill
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...
55
    {
56
        $ids = array();
57
58
        foreach ($this->getRecords() as $record) {
59
            array_push($ids, $record->ID);
60
            $record->markApproved();
61
        }
62
63
        $response = new HTTPResponse(Convert::raw2json(array(
64
            'done' => true,
65
            'records' => $ids
66
        )));
67
68
        $response->addHeader('Content-Type', 'text/json');
69
70
        return $response;
71
    }
72
}
73