Code Duplication    Length = 37-37 lines in 2 locations

src/Admin/CommentsGridFieldBulkAction/ApproveHandler.php 1 location

@@ 13-49 (lines=37) @@
10
/**
11
 * A {@link Handler} for bulk approving comments
12
 */
13
class ApproveHandler extends Handler
14
{
15
    private static $allowed_actions = ['index'];
16
17
    private static $url_segment = 'approve';
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)
32
    {
33
        $ids = [];
34
35
        foreach ($this->getRecords() as $record) {
36
            array_push($ids, $record->ID);
37
            $record->markApproved();
38
        }
39
40
        $response = new HTTPResponse(Convert::raw2json([
41
            'done' => true,
42
            'records' => $ids,
43
        ]));
44
45
        $response->addHeader('Content-Type', 'text/json');
46
47
        return $response;
48
    }
49
}
50

src/Admin/CommentsGridFieldBulkAction/SpamHandler.php 1 location

@@ 13-49 (lines=37) @@
10
/**
11
 * A {@link Handler} for bulk marking comments as spam
12
 */
13
class SpamHandler extends Handler
14
{
15
    private static $allowed_actions = ['index'];
16
17
    private static $url_segment = 'spam';
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)
32
    {
33
        $ids = [];
34
35
        foreach ($this->getRecords() as $record) {
36
            array_push($ids, $record->ID);
37
            $record->markSpam();
38
        }
39
40
        $response = new HTTPResponse(Convert::raw2json([
41
            'done' => true,
42
            'records' => $ids,
43
        ]));
44
45
        $response->addHeader('Content-Type', 'text/json');
46
47
        return $response;
48
    }
49
}
50