Completed
Pull Request — master (#69)
by Jakub
21:27 queued 10:37
created

manager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 4
crap 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\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 12
	public function test($ad_code)
44
	{
45
		$result = array(
46 12
			'notice'	=> array(),
47 12
			'warning'	=> array(),
48 12
		);
49 12
		foreach ($this->tests as $test)
50
		{
51 12
			$result = array_merge_recursive($result, $test->test($ad_code));
52 12
		}
53
54 12
		foreach ($result as $severity => $messages)
55
		{
56 12
			foreach ($messages as $lang_key)
57
			{
58 10
				$this->template->assign_block_vars('analyser_results_' . $severity, array(
59 10
					'MESSAGE'	=> $this->lang->lang($lang_key),
60 10
				));
61 12
			}
62 12
		}
63 12
	}
64
}
65