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 — parser ( 8d42bf )
by Eric
05:27
created

XmlParser::convertSnakeToCamelCase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMap\Service\Utility;
13
14
/**
15
 * @author GeLo <[email protected]>
16
 */
17
class XmlParser implements ParserInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function parse($data, array $options = [])
23
    {
24
        return $this->process(
25
            json_decode(json_encode(new \SimpleXMLElement($data)), true),
26
            isset($options['pluralization_rules']) ? $options['pluralization_rules'] : [],
27
            isset($options['snake_to_camel']) ? $options['snake_to_camel'] : false
28
        );
29
    }
30
31
    /**
32
     * @param mixed[]  $data
33
     * @param string[] $pluralizationRules
34
     * @param bool     $snakeToCamel
35
     *
36
     * @return mixed[]
37
     */
38
    private function process(array $data, array $pluralizationRules, $snakeToCamel)
39
    {
40
        foreach ($data as $attribute => $value) {
41
            if (isset($pluralizationRules[$attribute])) {
42
                $data[$pluralizationRules[$attribute]] = $value;
43
                unset($data[$attribute]);
44
45
                $attribute = $pluralizationRules[$attribute];
46
47
                if (!is_array($value) || is_string(key($value))) {
48
                    $data[$attribute] = [$value];
49
                }
50
            }
51
52
            if (is_array($data[$attribute])) {
53
                $data[$attribute] = $this->process($data[$attribute], $pluralizationRules, $snakeToCamel);
54
            }
55
56
            if ($snakeToCamel && is_string($attribute)
57
                && ($newAttribute = $this->snakeToCamel($attribute)) !== $attribute
58
            ) {
59
                $data[$newAttribute] = $data[$attribute];
60
                unset($data[$attribute]);
61
            }
62
        }
63
64
        return $data;
65
    }
66
67
    /**
68
     * @param string $data
69
     *
70
     * @return string
71
     */
72
    private function snakeToCamel($data)
73
    {
74
        return lcfirst(implode('', array_map(function ($word) {
75
            return ucfirst($word);
76
        }, explode('_', $data))));
77
    }
78
}
79