Total Complexity | 5 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class Utils |
||
13 | { |
||
14 | /** |
||
15 | * Returns a XML string content as a DOMDocument or as a formated XML string |
||
16 | * @throws InvalidArgumentException |
||
17 | * @param string|null $string |
||
18 | * @param bool $asDomDocument |
||
19 | * @return DOMDocument|string|null |
||
20 | */ |
||
21 | 22 | public static function getFormattedXml(?string $string, bool $asDomDocument = false) |
|
22 | { |
||
23 | 22 | if (!is_null($string)) { |
|
24 | 18 | $domDocument = self::getDOMDocument($string); |
|
25 | |||
26 | 12 | return $asDomDocument ? $domDocument : $domDocument->saveXML(); |
|
27 | } |
||
28 | |||
29 | 4 | return null; |
|
30 | } |
||
31 | |||
32 | /** |
||
33 | * @param string $string |
||
34 | * @return DOMDocument |
||
35 | * @throws InvalidArgumentException|ValueError |
||
36 | */ |
||
37 | 22 | public static function getDOMDocument(string $string): DOMDocument |
|
53 | } |
||
54 | } |
||
55 |