Completed
Push — next ( c05e12...5d0fe3 )
by Mathias
04:06
created

JobDescriptionFilter::filter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
ccs 14
cts 14
cp 1
cc 3
eloc 12
nc 3
nop 1
crap 3
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