PropertyAccessProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 27
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A updateEntity() 0 12 3
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