Completed
Pull Request — master (#73)
by Jakub
10:32
created

increment_controller   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 60
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 11 3
A clicks() 0 4 1
A views() 0 4 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
* Increment controller
15
*/
16
class increment_controller
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 7
	public function __construct(\phpbb\ads\ad\manager $manager, \phpbb\request\request $request)
31
	{
32 7
		$this->manager = $manager;
33 7
		$this->request = $request;
34 7
	}
35
36
	/**
37
	 * Handle request.
38
	 *
39
	 * @param	mixed	$data	Ad ID or ad IDs
40
	 * @param	string	$mode	clicks or views
41
	 * @return	\Symfony\Component\HttpFoundation\JsonResponse	A Symfony JsonResponse object
42
	 * @throws	\phpbb\exception\http_exception
43
	 */
44 7
	public function handle($data, $mode)
45
	{
46 7
		if (!empty($data) && $this->request->is_ajax())
47 7
		{
48 3
			$this->{$mode}($data);
49
50 3
			return new \Symfony\Component\HttpFoundation\JsonResponse();
51
		}
52
53 4
		throw new \phpbb\exception\http_exception(403, 'NOT_AUTHORISED');
54
	}
55
56
	/**
57
	 * Increment clicks for an ad.
58
	 *
59
	 * @param	int	$ad_id	Advertisement ID
60
	 */
61 1
	protected function clicks($ad_id)
62
	{
63 1
		$this->manager->increment_ad_clicks($ad_id);
64 1
	}
65
66
	/**
67
	 * Increment views for ads.
68
	 *
69
	 * @param	string	$ad_ids	Advertisement IDs
70
	 */
71 2
	protected function views($ad_ids)
72
	{
73 2
		$this->manager->increment_ads_views(explode('-', $ad_ids));
74 2
	}
75
}
76