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.

XmlRpcPayloadParser::parse()   C
last analyzed

Complexity

Conditions 13
Paths 14

Size

Total Lines 56

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 15.6406

Importance

Changes 0
Metric Value
dl 0
loc 56
c 0
b 0
f 0
ccs 21
cts 28
cp 0.75
rs 6.6166
cc 13
nc 14
nop 1
crap 15.6406

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Tools\Services\XmlRpc;
4
5
use DateTimeImmutable;
6
7
final class XmlRpcPayloadParser
8
{
9 11
    public static function parse(array $xml)
10
    {
11 11
        if (isset($xml['string'])) {
12 3
            return $xml['string'];
13
        }
14
15 9
        if (isset($xml['base64'])) {
16 1
            return base64_decode($xml['base64'], true);
17
        }
18
19 8
        if (isset($xml['i4'])) {
20 1
            return (int)$xml['i4'];
21
        }
22
23 7
        if (isset($xml['int'])) {
24 3
            return (int)$xml['int'];
25
        }
26
27 6
        if (isset($xml['double'])) {
28 1
            return (float)$xml['double'];
29
        }
30
31 5
        if (isset($xml['boolean'])) {
32 2
            return (bool)$xml['boolean'];
33
        }
34
35 3
        if (isset($xml['dateTime.iso8601'])) {
36 1
            return new DateTimeImmutable($xml['dateTime.iso8601']);
37
        }
38
39 2
        if (isset($xml['array'])) {
40
            $array = [];
41
42
            if (key($xml['array']['data']['value']) === 'struct') {
43
                $xml['array']['data']['value'] = [$xml['array']['data']['value']];
44
            }
45
46
            foreach ($xml['array']['data']['value'] as $item) {
47
                $array[] = self::parse($item);
48
            }
49
50
            return $array;
51
        }
52
53 2
        if (isset($xml['struct'])) {
54 2
            $struct = [];
55
56 2
            foreach ($xml['struct']['member'] as $member) {
57 2
                $struct[$member['name']] = self::parse($member['value']);
58
            }
59
60 2
            return $struct;
61
        }
62
63
        return $xml;
64
    }
65
}
66