Completed
Push — master ( 06e52a...98c39c )
by Pavel
13:39 queued 10:37
created

AssociationPropertyAccessor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 49
ccs 0
cts 26
cp 0
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setValue() 0 6 1
A getValue() 0 8 1
A isWritable() 0 4 1
A isReadable() 0 4 1
1
<?php
2
3
namespace ScayTrase\Api\Cruds\Adaptors\DoctrineOrm;
4
5
use Symfony\Bridge\Doctrine\ManagerRegistry;
6
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
7
8
final class AssociationPropertyAccessor implements PropertyAccessorInterface
9
{
10
    /** @var  PropertyAccessorInterface */
11
    private $delegate;
12
    /** @var  AssociationNormalizer */
13
    private $normalizer;
14
15
    /**
16
     * AssociationPropertyAccessor constructor.
17
     *
18
     * @param PropertyAccessorInterface $delegate
19
     * @param ManagerRegistry           $registry
20
     */
21
    public function __construct(PropertyAccessorInterface $delegate, ManagerRegistry $registry)
22
    {
23
        $this->delegate   = $delegate;
24
        $this->normalizer = new AssociationNormalizer($registry);
25
    }
26
27
    /** {@inheritdoc} */
28
    public function setValue(&$objectOrArray, $propertyPath, $value)
29
    {
30
        $value = $this->normalizer->denormalize($objectOrArray, $propertyPath, $value);
31
32
        return $this->delegate->setValue($objectOrArray, $propertyPath, $value);
33
    }
34
35
    /** {@inheritdoc} */
36
    public function getValue($objectOrArray, $propertyPath)
37
    {
38
        return $this->normalizer->normalize(
39
            $this->delegate->getValue($objectOrArray, $propertyPath),
40
            $objectOrArray,
41
            $propertyPath
42
        );
43
    }
44
45
    /** {@inheritdoc} */
46
    public function isWritable($objectOrArray, $propertyPath)
47
    {
48
        return $this->delegate->isWritable($objectOrArray, $propertyPath);
49
    }
50
51
    /** {@inheritdoc} */
52
    public function isReadable($objectOrArray, $propertyPath)
53
    {
54
        return $this->delegate->isReadable($objectOrArray, $propertyPath);
55
    }
56
}
57