ArrayUnserialiser::unserialise()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 12
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 3
eloc 6
nc 4
nop 2
crap 3.0261
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 ArrayUnserialiser.
19
 */
20
class ArrayUnserialiser 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
        if (!is_array($input)) {
31 3
            $input = eval("return $input;");
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
32 3
        }
33
34 6
        if (!is_null($class)) {
35
            return (new Mapper())->map($input, $class);
36
        }
37
38 6
        return $input;
39
    }
40
}
41