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

Xml   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 29
ccs 0
cts 25
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 10 1
A xmlJsonFix() 0 15 1
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