ArrayUnserialiser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 3
c 3
b 1
f 0
lcom 0
cbo 1
dl 0
loc 21
ccs 6
cts 7
cp 0.8571
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A unserialise() 0 12 3
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