Completed
Push — master ( 589f5d...2e0cd6 )
by Pavel
07:02
created

PropertyAccessProcessor::updateEntity()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 7
nc 3
nop 2
1
<?php
2
3
namespace ScayTrase\Api\Cruds;
4
5
use ScayTrase\Api\Cruds\Exception\EntityProcessingException;
6
use Symfony\Component\PropertyAccess\Exception\ExceptionInterface;
7
use Symfony\Component\PropertyAccess\PropertyAccessor;
8
9
final class PropertyAccessProcessor implements EntityProcessorInterface
10
{
11
    /** @var  PropertyAccessor */
12
    private $accessor;
13
14
    /**
15
     * PropertyAccessProcessor constructor.
16
     */
17
    public function __construct()
18
    {
19
        $this->accessor = new PropertyAccessor();
20
    }
21
22
    /** {@inheritdoc} */
23
    public function updateEntity($entity, $data)
24
    {
25
        try {
26
            foreach ((array)$data as $property => $value) {
27
                $this->accessor->setValue($entity, $property, $value);
28
            }
29
        } catch (ExceptionInterface $exception) {
30
            throw new EntityProcessingException($exception->getMessage(), $exception->getCode(), $exception);
31
        }
32
33
        return $entity;
0 ignored issues
show
Bug Compatibility introduced by
The expression return $entity; of type object|array is incompatible with the return type declared by the interface ScayTrase\Api\Cruds\Enti...Interface::updateEntity of type object as it can also be of type array which is not included in this return type.
Loading history...
34
    }
35
}
36