TransformHTMLLinks   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A transform() 0 11 2
1
<?php
2
3
/**
4
 * @author Jakob Sack <[email protected]>
5
 *
6
 * Mail
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\Mail\Service\HtmlPurify;
23
use HTMLPurifier_AttrTransform;
24
use HTMLPurifier_Config;
25
use HTMLPurifier_Context;
26
use HTMLPurifier_URIParser;
27
28
/**
29
 * Adds target="_blank" to all outbound links.
30
 */
31
class TransformHTMLLinks extends HTMLPurifier_AttrTransform
32
{
33
    /**
34
     * @type HTMLPurifier_URIParser
35
     */
36
    private $parser;
37
38 1
    public function __construct() {
39 1
        $this->parser = new HTMLPurifier_URIParser();
40 1
    }
41
42
    /**
43
     * @param array $attr
44
     * @param HTMLPurifier_Config $config
45
     * @param HTMLPurifier_Context $context
46
     * @return array
47
     */
48 1
    public function transform($attr, $config, $context)
49
    {
50 1
        if (!isset($attr['href'])) {
51 1
            return $attr;
52
        }
53
54
        // XXX Kind of inefficient
55 1
        $attr['target'] = '_blank';
56
57 1
        return $attr;
58
    }
59
}
60