ObjectConverter::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
namespace PeterColes\XmlSoccer\Converters;
4
5
use stdClass;
6
use SimpleXMLElement;
7
8
class ObjectConverter
9
{
10
    const STRINGS = [
11
        'AccountInformation'
12
    ];
13
14
    public function handle(SimpleXMLElement $xml)
15
    {
16
        $response = new stdClass;
17
18
        foreach ($xml->children() as $child) {
19
20
            $name = $child->getName();
21
22
            if (in_array($name, self::STRINGS)) {
23
                $response->$name = (string) $child;
24
            } else {
25
                $response->$name[ ] = $this->processChild($name, $child);
26
            }
27
        }
28
29
        return $response;
30
    }
31
32
    protected function processChild($name, $child)
33
    {
34
        if ($name == 'Match') {
35
            return (new Objects\Match)->handle($child);
36
        }  
37
38
        return (new Objects\Generic)->handle($child);
39
    }
40
}
41