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

XmlTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 33
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transformData() 0 17 4
A getExtensions() 0 6 1
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