Denormalizer::supportsDenormalization()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 3
eloc 1
nc 3
nop 3
crap 3
1
<?php
2
3
namespace Vox\Serializer;
4
5
use ReflectionClass;
6
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
7
use Vox\Data\ObjectHydratorInterface;
8
9
/**
10
 * a data denormalizer aimed to be used with the symfony serializer component
11
 * 
12
 * @author Jhonatan Teixeira <[email protected]>
13
 */
14
class Denormalizer implements DenormalizerInterface
15
{
16
    /**
17
     * @var ObjectHydratorInterface
18
     */
19
    private $hydrator;
20
    
21 44
    public function __construct(ObjectHydratorInterface $hydrator)
22
    {
23 44
        $this->hydrator = $hydrator;
24 44
    }
25
    
26 29
    public function denormalize($data, $class, $format = null, array $context = array())
27
    {
28 29
        if (is_string($class)) {
29 27
            $class = (new ReflectionClass($class))->newInstanceWithoutConstructor();
30
        }
31
        
32 29
        $this->hydrator->hydrate($class, $data);
33
        
34 29
        return $class;
35
    }
36
    
37 26
    public function supportsDenormalization($data, $type, $format = null)
38
    {
39 26
        return (is_object($type) || class_exists($type)) && is_array($data);
40
    }
41
}
42