Mapper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A map() 0 8 2
A arrayToObject() 0 4 1
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