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.

ConverterXML::convert()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 13
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 27
rs 9.5222
1
<?php
2
3
namespace Soheilrt\AdobeConnectClient\Client\Converter;
4
5
use InvalidArgumentException;
6
use Soheilrt\AdobeConnectClient\Client\Connection\ResponseInterface;
7
use Soheilrt\AdobeConnectClient\Client\Helpers\StringCaseTransform as SCT;
8
9
class ConverterXML implements ConverterInterface
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14
    public static function convert(ResponseInterface $response): array
15
    {
16
        $xml = simplexml_load_string($response->getBody());
17
18
        if ($xml === false) {
19
            throw new InvalidArgumentException('The response body needs be a valid XML');
20
        }
21
22
        $result = [];
23
24
        foreach ($xml as $element) {
25
            // If it has attributes it's an element
26
            if (!empty($element->attributes())) {
27
                $result[$element->getName()] = static::normalize(json_decode(json_encode($element), true));
28
                continue;
29
            }
30
31
            // if it doesn't have attributes it is a collection
32
            $elementName = SCT::toCamelCase($element->getName());
33
            $result[$elementName] = [];
34
35
            foreach ($element->children() as $elementChild) {
36
                $result[$elementName][] = static::normalize(json_decode(json_encode($elementChild), true));
37
            }
38
        }
39
40
        return $result;
41
    }
42
43
    /**
44
     * Recursive transform the array.
45
     *
46
     * @param array $arr The array piece
47
     *
48
     * @return array
49
     */
50
    protected static function normalize($arr): array
51
    {
52
        $ret = [];
53
54
        if (isset($arr['@attributes'])) {
55
            $arr = array_merge($arr, $arr['@attributes']);
56
            unset($arr['@attributes']);
57
        }
58
59
        foreach ($arr as $key => $value) {
60
            if (is_array($value)) {
61
                $value = static::normalize($value);
62
            }
63
            $ret[SCT::toCamelCase($key)] = $value;
64
        }
65
66
        return $ret;
67
    }
68
}
69