Mapper::map()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
crap 6
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\Utils;
13
14
/**
15
 * Class Mapper.
16
 */
17
class Mapper
18
{
19
    /**
20
     * @param $input
21
     * @param $class
22
     *
23
     * @return mixed
24
     */
25
    public function map($input, $class)
26
    {
27
        if (is_array($input)) {
28
            $input = $this->arrayToObject($input);
29
        }
30
31
        return (new \JsonMapper())->map($input, new $class());
32
    }
33
34
    /**
35
     * @param $input
36
     *
37
     * @return mixed
38
     */
39
    private function arrayToObject($input)
40
    {
41
        return json_decode(json_encode($input));
42
    }
43
}
44