ObjectConverter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 17 3
A processChild() 0 8 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