Completed
Push — master ( 607289...edbd19 )
by Pavel
01:31
created

AssociationPropertyAccessor::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 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  ManagerRegistry */
13
    private $registry;
14
    /** @var  AssociationNormalizer */
15
    private $normalizer;
16
17
    /**
18
     * AssociationPropertyAccessor constructor.
19
     *
20
     * @param PropertyAccessorInterface $delegate
21
     * @param ManagerRegistry           $registry
22
     */
23 6
    public function __construct(PropertyAccessorInterface $delegate, ManagerRegistry $registry)
24
    {
25 6
        $this->delegate = $delegate;
26 6
        $this->registry = $registry;
27
28 6
        $this->normalizer = new AssociationNormalizer($this->registry);
29 6
    }
30
31
    /** {@inheritdoc} */
32
    public function setValue(&$objectOrArray, $propertyPath, $value)
33
    {
34
        $value = $this->normalizer->denormalize($objectOrArray, $propertyPath, $value);
35
36
        return $this->delegate->setValue($objectOrArray, $propertyPath, $value);
37
    }
38
39
    /** {@inheritdoc} */
40 5
    public function getValue($objectOrArray, $propertyPath)
41
    {
42 5
        return $this->normalizer->normalize(
43 5
            $this->delegate->getValue($objectOrArray, $propertyPath),
44 5
            $objectOrArray,
45
            $propertyPath
46 5
        );
47
    }
48
49
    /** {@inheritdoc} */
50
    public function isWritable($objectOrArray, $propertyPath)
51
    {
52
        return $this->delegate->isWritable($objectOrArray, $propertyPath);
53
    }
54
55
    /** {@inheritdoc} */
56
    public function isReadable($objectOrArray, $propertyPath)
57
    {
58
        return $this->delegate->isReadable($objectOrArray, $propertyPath);
59
    }
60
}
61