AbstractXmlOutputParser::transformXmlToArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0185
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 4
    protected function transformXmlToArray(string $xmlString): array
13
    {
14 4
        if (mb_detect_encoding($xmlString, 'UTF-8', true) === false) {
15
            $xmlString = utf8_encode($xmlString);
16
        }
17
18 4
        $xml = simplexml_load_string($xmlString);
19 4
        $json = json_encode($xml);
20
21 4
        return json_decode($json, true);
22
    }
23
}
24