Xml::repair()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
namespace Tzsk\ScrapePod\Helpers;
3
4
use Exception;
5
use tidy;
6
7
class Xml
8
{
9
    /**
10
     * @param string $xml
11
     *
12
     * @return string
13
     * @throws Exception
14
     */
15
    public static function repair($xml)
16
    {
17
        if (class_exists("Tidy") === false) {
18
            throw new Exception("Tidy Class not found", 500);
19
        }
20
21
        $config = [
22
            'indent'     => true,
23
            'input-xml'  => true,
24
            'output-xml' => true,
25
            'wrap'       => false
26
        ];
27
28
        $xml_repaired = new Tidy();
29
        $xml_repaired->parseString($xml, $config, 'utf8');
30
        $xml_repaired->cleanRepair();
31
32
        return $xml_repaired;
33
    }
34
}
35