Conditions | 3 |
Paths | 4 |
Total Lines | 27 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 0 |
1 | <?php |
||
20 | public static function parseXmlResponseBody(?ResponseInterface $response, array $config = []) : SimpleXMLElement |
||
21 | { |
||
22 | $disableEntities = libxml_disable_entity_loader(); |
||
23 | $internalErrors = libxml_use_internal_errors(true); |
||
24 | try { |
||
25 | // Allow XML to be retrieved even if there is no response body |
||
26 | $xml = new SimpleXMLElement( |
||
27 | $response === null ? '<root />' : (string) $response->getBody(), |
||
28 | $config['libxml_options'] ?? LIBXML_NONET, |
||
29 | false, |
||
30 | $config['ns'] ?? '', |
||
31 | $config['ns_is_prefix'] ?? false |
||
32 | ); |
||
33 | libxml_disable_entity_loader($disableEntities); |
||
34 | libxml_use_internal_errors($internalErrors); |
||
35 | } catch (Throwable $exception) { |
||
36 | libxml_disable_entity_loader($disableEntities); |
||
37 | libxml_use_internal_errors($internalErrors); |
||
38 | |||
39 | throw new XmlParsingFailed( |
||
40 | 'Unable to parse response body into XML: ' . $exception->getMessage(), |
||
41 | 0, |
||
42 | $exception |
||
43 | ); |
||
44 | } |
||
45 | |||
46 | return $xml; |
||
47 | } |
||
49 |