Completed
Push — master ( e4a414...d6bcbc )
by Peter
05:51
created

ResponseRepair::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * AnimeDb package.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
9
 */
10
11
namespace AnimeDb\Bundle\WorldArtBrowserBundle\Service;
12
13
class ResponseRepair
14
{
15
    /**
16
     * @var \tidy
17
     */
18
    private $tidy;
19
20
    /**
21
     * @param \tidy $tidy
22
     */
23 2
    public function __construct(\tidy $tidy)
24
    {
25 2
        $this->tidy = $tidy;
26 2
    }
27
28
    /**
29
     * @param string $content
30
     *
31
     * @return string
32
     */
33 2
    public function repair($content)
34
    {
35 2
        if (!$content) {
36 1
            return '';
37
        }
38
39 1
        $content = iconv('windows-1251', 'utf-8', $content);
40
41
        // clean content
42
        $config = [
43 1
            'output-xhtml' => true,
44
            'indent' => true,
45
            'indent-spaces' => 0,
46
            'fix-backslash' => true,
47
            'hide-comments' => true,
48
            'drop-empty-paras' => true,
49
            'wrap' => false,
50
        ];
51 1
        $this->tidy->parseString($content, $config, 'utf8');
52 1
        $this->tidy->cleanRepair();
53 1
        $content = $this->tidy->root()->value;
54
55
        // ignore blocks
56 1
        $content = preg_replace('/<noembed>.*?<\/noembed>/is', '', $content);
57 1
        $content = preg_replace('/<noindex>.*?<\/noindex>/is', '', $content);
58
59 1
        return $content;
60
    }
61
}
62