CustomXmlDecoder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 2
c 2
b 0
f 1
lcom 1
cbo 0
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMimeType() 0 4 1
A decode() 0 7 1
1
<?php
2
namespace Michaels\Manager\Decoders;
3
4
use Michaels\Manager\Contracts\DecoderInterface;
5
6
/**
7
 * This is just a simple XML decoder for test purposes.
8
 *
9
 * SerializationTypeNotSupportedException
10
 * @package Michaels\Manager
11
 */
12
class CustomXmlDecoder implements DecoderInterface
13
{
14
    /** @var array Decoded data */
15
    protected $arrayData = [];
16
17
    /**
18
     * This is the method, which does the decoding work.
19
     *
20
     * @param $data
21
     * @return array
22
     */
23
    public function decode($data)
24
    {
25
        $xml = simplexml_load_string($data, "SimpleXMLElement", LIBXML_NOCDATA);
26
        $json = json_encode($xml);
27
        $this->arrayData = json_decode($json, true);
28
        return $this->arrayData;
29
    }
30
31
    /**
32
     * The data returned is the actual file extensions supported for the files to decode.
33
     * For instance, if you want to decode Yaml files with the extensions ".yml" and ".yaml",
34
     * then you want to set the return array to ['yaml', 'yml'].
35
     *
36
     * @return array
37
     */
38
    public function getMimeType()
39
    {
40
        return ['xml'];
41
    }
42
}
43