Skip to content

Commit 821593f

Browse files
committed
refactor getFormatedXml method
1 parent 061ed26 commit 821593f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Utils.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Utils
1414
*/
1515
public static function getFormatedXml($string, $asDomDocument = false)
1616
{
17+
$dom = null;
18+
$formated = $string;
1719
if (!empty($string) && class_exists('DOMDocument')) {
1820
$dom = new \DOMDocument('1.0', 'UTF-8');
1921
$dom->formatOutput = true;
@@ -23,12 +25,12 @@ public static function getFormatedXml($string, $asDomDocument = false)
2325
$dom->validateOnParse = false;
2426
try {
2527
if ($dom->loadXML($string)) {
26-
return $asDomDocument ? $dom : $dom->saveXML();
28+
$formated = $dom->saveXML();
2729
}
2830
} catch (\Exception $exception) {
29-
throw new \InvalidArgumentException(sprintf('XML string is invalid'), null, $exception);
31+
throw new \InvalidArgumentException('XML string is invalid', $exception->getCode(), $exception);
3032
}
3133
}
32-
return $asDomDocument ? null : $string;
34+
return $asDomDocument ? $dom : $formated;
3335
}
3436
}

0 commit comments

Comments
 (0)