Completed
Push — master ( a6c8f9...b97be3 )
by Vladimir
03:52 queued 19s
created

XmlTransformer::transformData()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.016

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 10
cp 0.9
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 3
nop 1
crap 4.016
1
<?php
2
3
/**
4
 * @copyright 2017 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\DataTransformer;
9
10
use allejo\stakx\Exception\DependencyMissingException;
11
12
class XmlTransformer implements DataTransformer
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17 3
    public static function transformData($content)
18
    {
19 3
        if (!function_exists('simplexml_load_string'))
20 3
        {
21
            throw new DependencyMissingException('XML', 'XML support is not available with the current PHP installation.');
22
        }
23
24 3
        libxml_use_internal_errors(true);
25 3
        $data = json_decode(json_encode(simplexml_load_string($content)), true);
26
27 3
        if ($data === false || $data === null)
28 3
        {
29 1
            return [];
30
        }
31
32 2
        return $data;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 7
    public static function getExtensions()
39
    {
40
        return [
41 7
            'xml',
42 7
        ];
43
    }
44
}
45