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

src/Admin/CommentsGridFieldBulkAction/Handler.php (4 issues)

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
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
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
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
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
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