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

script_without_async   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 18 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\test;
12
13
class script_without_async implements test_interface
14
{
15
	/**
16
	 * {@inheritDoc}
17
	 *
18
	 * Synchronously loaded scripts test.
19
	 * This test looks for scripts that aren't using `async` attribute
20
	 * to load itself asynchronously. Such scripts slow down page rendering
21
	 * time and should be made asynchronous.
22
	 */
23 13
	public function run($ad_code)
24
	{
25 13
		if (preg_match_all('/&lt;script(.*)src(.*)&gt;/U', $ad_code, $matches))
26 13
		{
27 8
			foreach ($matches[1] as $match)
28
			{
29 8
				if (!preg_match('/ async/', $match))
30 8
				{
31
					return array(
32 5
						'severity'	=> 'notice',
33 5
						'message'	=> 'SCRIPT_WITHOUT_ASYNC',
34 5
					);
35
				}
36 4
			}
37 3
		}
38
39 8
		return false;
40
	}
41
}
42