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.
Completed
Push — master ( 88c052...ed9db1 )
by Nathan
10s
created

XML   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 87.88%

Importance

Changes 5
Bugs 1 Features 2
Metric Value
c 5
b 1
f 2
dl 0
loc 62
ccs 29
cts 33
cp 0.8788
rs 10
wmc 11
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 14 3
C recursive_parse() 0 35 8
1
<?php
2
3
namespace Nathanmac\Utilities\Parser\Formats;
4
5
use Nathanmac\Utilities\Parser\Exceptions\ParserException;
6
7
/**
8
 * XML Formatter
9
 *
10
 * @package    Nathanmac\Utilities\Parser\Formats
11
 * @author     Nathan Macnamara <[email protected]>
12
 * @license    https://github.com/nathanmac/Parser/blob/master/LICENSE.md  MIT
13
 */
14
class XML implements FormatInterface
15
{
16
    /**
17
     * Parse Payload Data
18
     *
19
     * @param string $payload
20
     *
21
     * @throws ParserException
22
     * @return array
23
     *
24
     */
25 30
    public function parse($payload)
26
    {
27 30
        if ($payload) {
28
            try {
29 27
                $xml = simplexml_load_string($payload, 'SimpleXMLElement', LIBXML_NOCDATA);
30 24
                $ns = ['' => null] + $xml->getDocNamespaces(true);
31 24
                return $this->recursive_parse($xml, $ns);
32 3
            } catch (\Exception $ex) {
33 3
                throw new ParserException('Failed To Parse XML');
34
            }
35
        }
36
37 3
        return [];
38
    }
39
40 24
    protected function recursive_parse($xml, $ns)
41
    {
42 24
        $result = (string) $xml;
43
44 24
        foreach ($ns as $nsName => $nsUri) {
45 24
            foreach ($xml->attributes($nsUri) as $attName => $attValue) {
46 6
                if ( ! empty($nsName)) {
47
                    $attName = "{$nsName}:{$attName}";
48
                }
49
50 6
                $result["@{$attName}"] = $attValue;
51 24
            }
52
53 24
            foreach ($xml->children($nsUri) as $childName => $child) {
54 24
                if ( ! empty($nsName)) {
55 6
                    $childName = "{$nsName}:{$childName}";
56 6
                }
57
58 24
                $child = $this->recursive_parse($child, $ns);
59
60 24
                if (isset($result[$childName])) {
61 6
                    if (is_numeric(key($result[$childName]))) {
62
                        $result[$childName][] = $child;
63
                    } else {
64 6
                        $temp = $result[$childName];
65 6
                        $result[$childName] = [$temp, $child];
66
                    }
67 6
                } else {
68 24
                    $result[$childName] = $child;
69
                }
70 24
            }
71 24
        }
72
73 24
        return $result;
74
    }
75
}
76