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

AssociationPropertyAccessor::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 2
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