PropertyAccessProcessor::updateEntity()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 4
cts 6
cp 0.6667
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 2
crap 3.3332
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 10
    public function __construct()
18
    {
19 10
        $this->accessor = new PropertyAccessor();
20 10
    }
21
22
    /** {@inheritdoc} */
23 10
    public function updateEntity($entity, $data)
24
    {
25
        try {
26 10
            foreach ((array)$data as $property => $value) {
27 10
                $this->accessor->setValue($entity, $property, $value);
28
            }
29
        } catch (ExceptionInterface $exception) {
30
            throw new EntityProcessingException($exception->getMessage(), $exception->getCode(), $exception);
31
        }
32
33 10
        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