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

untrusted_connection::run()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 2
nop 1
crap 3
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\test;
12
13
class untrusted_connection implements test_interface
14
{
15
	/** @var \phpbb\request\request */
16
	protected $request;
17
18
	/**
19
	 * Construct an ad code analysis manager object
20
	 *
21
	 * @param \phpbb\request\request $request Request object
22
	 */
23 12
	public function __construct(\phpbb\request\request $request)
24
	{
25 12
		$this->request = $request;
26 12
	}
27
28
	/**
29
	 * {@inheritDoc}
30
	 *
31
	 * Untrusted connection test.
32
	 * When board runs on HTTPS and ad tries to load a file from
33
	 * HTTP source, browser throws a warning. We should prevent that.
34
	 */
35 12
	public function run($ad_code)
36
	{
37 12
		$is_https = $this->request->server('HTTPS', false);
38 12
		if ($is_https && preg_match('/http[^s]/', $ad_code))
39 12
		{
40
			return array(
41
				'warning'	=> array(
42 2
					'UNSECURE_CONNECTION',
43 2
				),
44 2
			);
45
		}
46
47 10
		return array();
48
	}
49
}
50