Passed
Branch master (2530fd)
by Kazi Mainuddin
03:16
created

Xml::repair()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 12
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
}