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

script_without_async   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
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 30
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 19 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 12
	public function run($ad_code)
24
	{
25 12
		if (preg_match_all('/&lt;script(.*)&gt;/U', $ad_code, $matches))
26 12
		{
27 12
			foreach ($matches[1] as $match)
28
			{
29 12
				if (!preg_match('/ async/', $match))
30 12
				{
31
					return array(
32
						'notice'	=> array(
33 5
							'SCRIPT_WITHOUT_ASYNC',
34 5
						),
35 5
					);
36
				}
37 8
			}
38 7
		}
39
40 7
		return array();
41
	}
42
}
43