Completed
Push — master ( bd25e7...98ff1d )
by Maxime
33s
created

AbstractXmlOutputParser::transformXmlToArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 11
ccs 5
cts 7
cp 0.7143
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2.0932
1
<?php
2
3
namespace Mhor\MediaInfo\Parser;
4
5
abstract class AbstractXmlOutputParser implements OutputParserInterface
6
{
7
    /**
8
     * @param string $xmlString
9
     *
10
     * @return array
11
     */
12 3
    protected function transformXmlToArray($xmlString)
13
    {
14 3
        if (mb_detect_encoding($xmlString, 'UTF-8', true) === false) {
15
            $xmlString = utf8_encode($xmlString);
16
        }
17
18 3
        $xml = simplexml_load_string($xmlString);
19 3
        $json = json_encode($xml);
20
21 3
        return json_decode($json, true);
22
    }
23
}
24