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   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 32
rs 10
c 0
b 0
f 0
ccs 0
cts 19
cp 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseXmlResponseBody() 0 27 3
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