Completed
Push — master ( 98c39c...c8155d )
by Pavel
16:50
created

JmsSerializerProcessor::updateEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1.037

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 9
cp 0.6667
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 1.037
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Adaptors\JmsSerializer;
4
5
use JMS\Serializer\ArrayTransformerInterface as JmsDenormalizerInterface;
6
use ScayTrase\Api\Cruds\EntityProcessorInterface;
7
8
final class JmsSerializerProcessor implements EntityProcessorInterface
9
{
10
    /** @var JmsDenormalizerInterface */
11
    private $denormalizer;
12
13
    /**
14
     * JmsSerializerProcessor constructor.
15
     *
16
     * @param JmsDenormalizerInterface $denormailzer
17
     */
18 2
    public function __construct(JmsDenormalizerInterface $denormailzer)
19
    {
20 2
        $this->denormalizer = $denormailzer;
21 2
    }
22
23
    /** {@inheritdoc} */
24 2
    public function updateEntity($entity, $data)
25
    {
26 2
        $this->denormalizer->fromArray(
27 2
            $data,
28 2
            get_class($entity),
29 2
            JmsContextFactory::deserialization(['object_to_populate' => $entity])
30
        );
31
32 2
        return $entity;
33
    }
34
}
35