Completed
Push — master ( f9651b...451a88 )
by Matt
30s queued 13s
created

untrusted_connection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 36
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 13 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 13
	public function __construct(\phpbb\request\request $request)
24
	{
25 13
		$this->request = $request;
26 13
	}
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 13
	public function run($ad_code)
36
	{
37 13
		$is_https = $this->request->server('HTTPS', false);
38 13
		if ($is_https && preg_match('/http[^s]/', $ad_code))
39 13
		{
40
			return array(
41 2
				'severity'	=> 'warning',
42 2
				'message'	=> 'UNSECURE_CONNECTION',
43 2
			);
44
		}
45
46 11
		return false;
47
	}
48
}
49