GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Parser::parseXmlResponseBody()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 18
nc 4
nop 2
dl 0
loc 27
rs 9.6666
c 0
b 0
f 0
ccs 0
cts 19
cp 0
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimPod\SmsManager;
6
7
use Psr\Http\Message\ResponseInterface;
8
use SimpleXMLElement;
9
use SimPod\SmsManager\Exception\XmlParsingFailed;
10
use Throwable;
11
use function libxml_disable_entity_loader;
12
use function libxml_use_internal_errors;
13
use const LIBXML_NONET;
14
15
class Parser
16
{
17
    /**
18
     * @param mixed[] $config
19
     */
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
    }
48
}
49