Completed
Pull Request — master (#63)
by Jakub
30:38
created

view_controller   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 40
loc 40
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A increment_views() 13 13 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 *
4
 * Advertisement management. An extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2017 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\ads\controller;
12
13
/**
14
 * View controller
15
 */
16 View Code Duplication
class view_controller
0 ignored issues
show
Duplication introduced by
This class 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...
17
{
18
	/** @var \phpbb\ads\ad\manager */
19
	protected $manager;
20
21
	/** @var \phpbb\request\request */
22
	protected $request;
23
24
	/**
25
	 * Constructor
26
	 *
27
	 * @param \phpbb\ads\ad\manager    $manager Advertisement manager object
28
	 * @param \phpbb\request\request   $request	Request object
29
	 */
30
	public function __construct(\phpbb\ads\ad\manager $manager, \phpbb\request\request $request)
31
	{
32
		$this->manager = $manager;
33
		$this->request = $request;
34
	}
35
36
	/**
37
	 * Increment views for ads
38
	 *
39
	 * @param	string	$ad_ids	Advertisement IDs
40
	 * @return	\Symfony\Component\HttpFoundation\JsonResponse	A Symfony JsonResponse object
41
	 */
42
	public function increment_views($ad_ids)
43
	{
44
		$ad_ids = explode('-', $ad_ids);
45
46
		if ($this->request->is_ajax())
47
		{
48
			$this->manager->increment_ads_views($ad_ids);
49
50
			return new \Symfony\Component\HttpFoundation\JsonResponse();
51
		}
52
53
		throw new \phpbb\exception\http_exception(403, 'NOT_AUTHORISED');
54
	}
55
}
56