Test Failed
Push — master ( 25b8d1...f70cb8 )
by Pavel
03:49
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\Adaptors\Symfony;
4
5
use ScayTrase\Api\Cruds\EntityProcessorInterface;
6
use ScayTrase\Api\Cruds\Exception\EntityProcessingException;
7
use Symfony\Component\PropertyAccess\Exception\ExceptionInterface;
8
use Symfony\Component\PropertyAccess\PropertyAccessor;
9
10
final class PropertyAccessProcessor implements EntityProcessorInterface
11
{
12
    /** @var  PropertyAccessor */
13
    private $accessor;
14
15
    /**
16
     * PropertyAccessProcessor constructor.
17
     */
18
    public function __construct()
19
    {
20
        $this->accessor = new PropertyAccessor();
21
    }
22
23
    /** {@inheritdoc} */
24
    public function updateEntity($entity, $data)
25
    {
26
        try {
27
            foreach ((array)$data as $property => $value) {
28
                $this->accessor->setValue($entity, $property, $value);
29
            }
30
        } catch (ExceptionInterface $exception) {
31
            throw new EntityProcessingException($exception->getMessage(), $exception->getCode(), $exception);
32
        }
33
34
        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...
35
    }
36
}
37