Completed
Push — master ( 30d679...ef761f )
by Adam
07:29
created

Xml::xmlJsonFix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 15
ccs 0
cts 15
cp 0
rs 9.4285
cc 1
eloc 10
nc 1
nop 1
crap 2
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 $this->xmlJsonFix(
12
            simplexml_load_string(
13
                $this->getValue(),
14
                'SimpleXMLElement',
15
                LIBXML_NOCDATA
16
            )
17
        );
18
    }
19
20
    private function xmlJsonFix($xml)
21
    {
22
        return json_decode(
23
            str_replace(
24
                ':[]',
25
                ':null',
26
                str_replace(
27
                    ':{}',
28
                    ':null',
29
                    json_encode((array) $xml)
30
                )
31
            ),
32
            1
33
        );
34
    }
35
}
36