Code Duplication    Length = 20-22 lines in 3 locations

code/controllers/CommentingController.php 3 locations

@@ 237-256 (lines=20) @@
234
	/**
235
	 * Marks a given {@link Comment} as spam. Removes the comment from display
236
	 */
237
	public function spam() {
238
		$comment = $this->getComment();
239
		if(!$comment) return $this->httpError(404);
240
		if(!$comment->canEdit()) {
241
			return Security::permissionFailure($this, 'You do not have permission to edit this comment');
242
		}
243
		if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
244
245
		$comment->markSpam();
246
        if (empty($this->getRequest()->getHeader('Referer'))) {
247
            return $this->request->isAjax()
248
                ? $comment->renderWith('CommentsInterface_singlecomment')
249
                : $this->redirectBack();
250
        } else {
251
            $url = $this->getRequest()->getHeader('Referer') . '#comment-' . $comment->ID;
252
            return $this->request->isAjax()
253
                ? $comment->renderWith('CommentsInterface_singlecomment')
254
                : $this->redirect($url);
255
        }
256
	}
257
258
	/**
259
	 * Marks a given {@link Comment} as ham (not spam).
@@ 261-280 (lines=20) @@
258
	/**
259
	 * Marks a given {@link Comment} as ham (not spam).
260
	 */
261
	public function ham() {
262
		$comment = $this->getComment();
263
		if(!$comment) return $this->httpError(404);
264
		if(!$comment->canEdit()) {
265
			return Security::permissionFailure($this, 'You do not have permission to edit this comment');
266
		}
267
		if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
268
269
		$comment->markApproved();
270
        if (empty($this->getRequest()->getHeader('Referer'))) {
271
            return $this->request->isAjax()
272
                ? $comment->renderWith('CommentsInterface_singlecomment')
273
                : $this->redirectBack();
274
        } else {
275
            $url = $this->getRequest()->getHeader('Referer') . '#comment-' . $comment->ID;
276
            return $this->request->isAjax()
277
                ? $comment->renderWith('CommentsInterface_singlecomment')
278
                : $this->redirect($url);
279
        }
280
	}
281
282
	/**
283
	 * Marks a given {@link Comment} as approved.
@@ 285-306 (lines=22) @@
282
	/**
283
	 * Marks a given {@link Comment} as approved.
284
	 */
285
	public function approve() {
286
		$comment = $this->getComment();
287
		if(!$comment) return $this->httpError(404);
288
		if(!$comment->canEdit()) {
289
			return Security::permissionFailure($this, 'You do not have permission to approve this comment');
290
		}
291
		if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
292
293
		$comment->markApproved();
294
295
        if (empty($this->getRequest()->getHeader('Referer'))) {
296
            return $this->request->isAjax()
297
                ? $comment->renderWith('CommentsInterface_singlecomment')
298
                : $this->redirectBack();
299
        } else {
300
            $url = $this->getRequest()->getHeader('Referer') . '#comment-' . $comment->ID;
301
            return $this->request->isAjax()
302
                ? $comment->renderWith('CommentsInterface_singlecomment')
303
                : $this->redirect($url);
304
        }
305
306
	}
307
308
	/**
309
	 * Returns the comment referenced in the URL (by ID). Permission checking