Code Duplication    Length = 15-19 lines in 4 locations

src/Controllers/CommentingController.php 4 locations

@@ 295-313 (lines=19) @@
292
    /**
293
     * Deletes a given {@link Comment} via the URL.
294
     */
295
    public function delete()
296
    {
297
        $comment = $this->getComment();
298
        if (!$comment) {
299
            return $this->httpError(404);
300
        }
301
        if (!$comment->canDelete()) {
302
            return Security::permissionFailure($this, 'You do not have permission to delete this comment');
303
        }
304
        if (!$comment->getSecurityToken()->checkRequest($this->request)) {
305
            return $this->httpError(400);
306
        }
307
308
        $comment->delete();
309
310
        return $this->request->isAjax()
311
            ? true
312
            : $this->redirectBack();
313
    }
314
315
    /**
316
     * Marks a given {@link Comment} as spam. Removes the comment from display
@@ 318-333 (lines=16) @@
315
    /**
316
     * Marks a given {@link Comment} as spam. Removes the comment from display
317
     */
318
    public function spam()
319
    {
320
        $comment = $this->getComment();
321
        if (!$comment) {
322
            return $this->httpError(404);
323
        }
324
        if (!$comment->canEdit()) {
325
            return Security::permissionFailure($this, 'You do not have permission to edit this comment');
326
        }
327
        if (!$comment->getSecurityToken()->checkRequest($this->request)) {
328
            return $this->httpError(400);
329
        }
330
331
        $comment->markSpam();
332
        return $this->renderChangedCommentState($comment);
333
    }
334
335
    /**
336
     * Marks a given {@link Comment} as ham (not spam).
@@ 338-353 (lines=16) @@
335
    /**
336
     * Marks a given {@link Comment} as ham (not spam).
337
     */
338
    public function ham()
339
    {
340
        $comment = $this->getComment();
341
        if (!$comment) {
342
            return $this->httpError(404);
343
        }
344
        if (!$comment->canEdit()) {
345
            return Security::permissionFailure($this, 'You do not have permission to edit this comment');
346
        }
347
        if (!$comment->getSecurityToken()->checkRequest($this->request)) {
348
            return $this->httpError(400);
349
        }
350
351
        $comment->markApproved();
352
        return $this->renderChangedCommentState($comment);
353
    }
354
355
    /**
356
     * Marks a given {@link Comment} as approved.
@@ 358-372 (lines=15) @@
355
    /**
356
     * Marks a given {@link Comment} as approved.
357
     */
358
    public function approve()
359
    {
360
        $comment = $this->getComment();
361
        if (!$comment) {
362
            return $this->httpError(404);
363
        }
364
        if (!$comment->canEdit()) {
365
            return Security::permissionFailure($this, 'You do not have permission to approve this comment');
366
        }
367
        if (!$comment->getSecurityToken()->checkRequest($this->request)) {
368
            return $this->httpError(400);
369
        }
370
        $comment->markApproved();
371
        return $this->renderChangedCommentState($comment);
372
    }
373
374
    /**
375
     * Redirect back to referer if available, ensuring that only site URLs