YamlUnserialiser::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 1
Bugs 0 Features 0
Metric Value
c 1
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
use Symfony\Component\Yaml\Yaml;
17
18
/**
19
 * Class YamlUnserialiser.
20
 */
21
class YamlUnserialiser implements Unserialiser
22
{
23
    /**
24
     * @param $input
25
     * @param null $class
26
     *
27
     * @return mixed
28
     */
29 6
    public function unserialise($input, $class = null)
30
    {
31 6
        $contents = Yaml::parse($input);
32
33 6
        if (!is_null($class)) {
34
            return (new Mapper())->map($contents, $class);
35
        }
36
37 6
        return $contents;
38
    }
39
}
40