Passed
Branch master (dd75d0)
by Peter
02:45
created

ObjectConverter::processChild()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
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