ResponseRepair   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 53
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A repair() 0 19 2
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
     * @var array
22
     */
23
    private $config = [
24
        'output-xhtml' => true,
25
        'indent' => true,
26
        'indent-spaces' => 0,
27
        'fix-backslash' => true,
28
        'hide-comments' => true,
29
        'drop-empty-paras' => true,
30
        'wrap' => false,
31
    ];
32
33
    /**
34
     * @param \tidy $tidy
35
     */
36 2
    public function __construct(\tidy $tidy)
37
    {
38 2
        $this->tidy = $tidy;
39 2
    }
40
41
    /**
42
     * @param string $content
43
     *
44
     * @return string
45
     */
46 2
    public function repair($content)
47
    {
48 2
        if (!$content) {
49 1
            return '';
50
        }
51
52 1
        $content = iconv('windows-1251', 'utf-8', $content);
53
54
        // clean content
55 1
        $this->tidy->parseString($content, $this->config, 'utf8');
56 1
        $this->tidy->cleanRepair();
57 1
        $content = $this->tidy->root()->value;
58
59
        // ignore blocks
60 1
        $content = preg_replace('/<noembed>.*?<\/noembed>/is', '', $content);
61 1
        $content = preg_replace('/<noindex>.*?<\/noindex>/is', '', $content);
62
63 1
        return $content;
64
    }
65
}
66