XmlUnserialiser::unserialise()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
crap 2.032
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