Completed
Pull Request — master (#69)
by Jakub
10:18
created

manager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 59
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B run() 0 23 4
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\analyser;
12
13
class manager
14
{
15
	/** @var array Ad code analysis tests */
16
	protected $tests;
17
18
	/** @var \phpbb\request\request */
19
	protected $request;
20
21
	/** @var \phpbb\template\template */
22
	protected $template;
23
24
	/** @var \phpbb\language\language */
25
	protected $lang;
26
27
	/**
28
	 * Construct an ad code analysis manager object
29
	 *
30
	 * @param	array						$tests		Ad code analysis tests passed via the service container
31
	 * @param	\phpbb\request\request		$request	Request object
32
	 * @param	\phpbb\template\template	$template	Template object
33
	 * @param	\phpbb\language\language	$lang		Language object
34
	 */
35 12
	public function __construct($tests, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\language\language $lang)
36
	{
37 12
		$this->tests = $tests;
38 12
		$this->request = $request;
39 12
		$this->template = $template;
40 12
		$this->lang = $lang;
41 12
	}
42
43
	/**
44
	 * Test the ad code for potential problems.
45
	 *
46
	 * @param	string	$ad_code	Advertisement code
47
	 */
48 12
	public function run($ad_code)
49
	{
50
		$result = array(
51 12
			'notice'	=> array(),
52 12
			'warning'	=> array(),
53 12
		);
54 12
		foreach ($this->tests as $test)
55
		{
56 12
			$result = array_merge_recursive($result, $test->run($ad_code));
57 12
		}
58
59 12
		foreach ($result as $severity => $messages)
60
		{
61 12
			foreach ($messages as $lang_key)
62
			{
63 10
				$this->template->assign_block_vars('analyser_results_' . $severity, array(
64 10
					'MESSAGE'	=> $this->lang->lang($lang_key),
65 10
				));
66 12
			}
67 12
		}
68
69 12
		$this->template->assign_var('CODE_ANALYSED', true);
70 12
	}
71
}
72