JobDescriptionFilter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace StackoverflowApi\Client;
12
13
use Zend\Filter\StripTags;
14
15
/**
16
 * ${CARET}
17
 * 
18
 * @author Mathias Gelhausen <[email protected]>
19
 * @todo write test 
20
 */
21
class JobDescriptionFilter extends StripTags
22
{
23 1
    public function __construct()
24
    {
25 1
        parent::__construct([
26 1
            'b', 'strong', 'p', 'ul', 'li', 'ol', 'table', 'tr', 'td', 'tbody',
27 1
            'thead', 'th', 'br', 'i', 'em'
28 1
        ]);
29 1
    }
30
31 1
    public function filter($value)
32
    {
33 1
        $oldErrorReporting = error_reporting(0);
34 1
        $dom = new \DOMDocument();
35 1
        $dom->loadHTMLFile($value);
36
37 1
        $body = $dom->getElementsByTagName('body')->item(0);
38
39 1
        foreach (['script', 'style'] as $name) {
40 1
            while ($elem = $body->getElementsByTagName($name)->item(0)) {
41 1
                $elem->parentNode->removeChild($elem);
42 1
            }
43 1
        }
44
45 1
        $html = $dom->saveHTML($body);
46 1
        error_reporting($oldErrorReporting);
47
48 1
        $html = parent::filter($html);
49
50 1
        return $html;
51
    }
52
53
54
}
55