ContentPurifier   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 33
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A purify() 0 3 1
1
<?php
2
3
namespace GitHub;
4
5
use HTMLPurifier;
6
use HTMLPurifier_Config;
7
8
/**
9
 * @licence GNU GPL v2+
10
 * @author Jeroen De Dauw < [email protected] >
11
 */
12
class ContentPurifier {
13
14
	/**
15
	 * @var HTMLPurifier
16
	 */
17
	private $purifier;
18
19
	const ALLOWED_HTML_TAGS = '
20
		h1,h2,h3,h4,h5,h6,
21
		p,
22
		br,hr,
23
		ul,ol,li,
24
		span,b,i,u,strong,em,
25
		a[href|target],
26
		img[src|alt],
27
		table[class],thead,tbody,tr,th[scope],td[scope],
28
		code,pre
29
	';
30
31 4
	public function __construct() {
32 4
		$config = HTMLPurifier_Config::createDefault();
33
34 4
		$config->set( 'HTML.Allowed', self::ALLOWED_HTML_TAGS );
35 4
		$config->set( 'Attr.AllowedFrameTargets', [ '_blank' ] ); // allow target="_blank" hrefs
36
37 4
		$this->purifier = new HTMLPurifier( $config );
38 4
	}
39
40 4
	public function purify( string $html ): string {
41 4
		return $this->purifier->purify( $html );
42
	}
43
44
}
45