XmlUnserialiser   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 80%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 19
ccs 4
cts 5
cp 0.8
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A unserialise() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of Payload.
5
 *
6
 * (c) DraperStudio <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace DraperStudio\Payload\Unserialisers;
13
14
use DraperStudio\Payload\Contracts\Unserialiser;
15
use DraperStudio\Payload\Utils\Mapper;
16
17
/**
18
 * Class XmlUnserialiser.
19
 */
20
class XmlUnserialiser implements Unserialiser
21
{
22
    /**
23
     * @param $input
24
     * @param null $class
25
     *
26
     * @return mixed
27
     */
28 6
    public function unserialise($input, $class = null)
29
    {
30 6
        $contents = json_decode(json_encode(simplexml_load_string($input, null, LIBXML_NOCDATA)));
31
32 6
        if (!is_null($class)) {
33
            return (new Mapper())->map($contents, $class);
34
        }
35
36 6
        return (array) $contents;
37
    }
38
}
39