Completed
Push — master ( 18bfc7...82e0b5 )
by Jens
18:00 queued 05:19
created

JsonObjectMapper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 35
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A map() 0 5 1
A of() 0 4 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model;
7
8
use Commercetools\Core\Model\Common\Context;
9
use Commercetools\Core\Model\Common\JsonDeserializeInterface;
10
11
class JsonObjectMapper implements MapperInterface
12
{
13
    private $context;
14
15
    /**
16
     * JsonObjectMapper constructor.
17
     * @param $class
18
     * @param Context $context
19
     */
20 567
    public function __construct(Context $context = null)
21
    {
22 567
        $this->context = $context;
23 567
    }
24
25
    /**
26
     * @param array $data
27
     * @param string $class class to map the data to
28
     * @return JsonDeserializeInterface|null
29
     */
30 567
    public function map(array $data, $class)
31
    {
32 567
        $object = forward_static_call_array([$class, 'fromArray'], [$data, $this->context]);
33 567
        return $object;
34
    }
35
36
    /**
37
     * @param $class
38
     * @param Context $context
39
     * @return static
40
     */
41 567
    public static function of(Context $context = null)
42
    {
43 567
        return new static($context);
44
    }
45
}
46