Utility::parseXml()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
/**
3
 * Slince shipment tracker library
4
 * @author Tao <[email protected]>
5
 */
6
namespace Slince\ShipmentTracking;
7
8
use Slince\ShipmentTracking\Foundation\Exception\InvalidArgumentException;
9
10
final class Utility
11
{
12
    /**
13
     * Parse the xml to an array
14
     * @param string $xml
15
     * @throws
16
     * @return array
17
     */
18
    public static function parseXml($xml)
19
    {
20
        libxml_use_internal_errors(true);
21
        $data = simplexml_load_string($xml, null, LIBXML_NOERROR);
22
        if ($data === false) {
23
            throw new InvalidArgumentException(sprintf('Invalid xml response "%s"', $xml));
24
        }
25
        return json_decode(json_encode($data), true);
26
    }
27
}