Completed
Push — master ( 2c45d8...dee3e5 )
by Adam
05:11
created

Xml::getXml()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
3
namespace BestServedCold\PhalueObjects\Format;
4
5
use BestServedCold\PhalueObjects\Format;
6
7
final class Xml extends Format
8
{
9
    public function parse()
10
    {
11
        return (array) $this->objectify($this->getValue());
12
    }
13
14
    private function getXml($value)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
15
    {
16
        return is_string($value)
17
            ? simplexml_load_string($value, 'SimpleXMLElement', LIBXML_NOCDATA)
18
            : $value;
19
    }
20
21
    
22
    private function objectify($value)
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
23
    {
24
        $temp = $this->getXml($value);
25
26
        $result = [];
27
28
        foreach ((array) $temp as $key => $value) {
29
            $result[$key] = (is_array($value) || is_object($value))
30
                ? $this->objectify($value)
31
                : $value;
32
        }
33
34
        return $result;
35
    }
36
}
37