Test Failed
Push — master ( ab4f5a...dbca4e )
by Jeroen De
04:59
created

ContentPurifier   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 32
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
	';
29
30
	public function __construct() {
31
		$config = HTMLPurifier_Config::createDefault();
32
33
		$config->set( 'HTML.Allowed', self::ALLOWED_HTML_TAGS );
34
		$config->set( 'Attr.AllowedFrameTargets', [ '_blank' ] ); // allow target="_blank" hrefs
35
36
		$this->purifier = new HTMLPurifier( $config );
37
	}
38
39
	public function purify( string $html ): string {
40
		return $this->purifier->purify( $html );
41
	}
42
43
}
44