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

view_controller::increment_views()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 13
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 13
loc 13
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
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