Test Failed
Push — master ( 72a6c5...9329b7 )
by Arun
03:52
created

DoctrineCollectionFilter::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 3
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace DeepCopy\Filter\Doctrine;
4
5
use DeepCopy\Filter\Filter;
6
use ReflectionProperty;
7
8
/**
9
 * Set a null value for a property
10
 */
11
class DoctrineCollectionFilter implements Filter
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16
    public function apply($object, $property, $objectCopier)
17
    {
18
        $reflectionProperty = new ReflectionProperty($object, $property);
19
20
        $reflectionProperty->setAccessible(true);
21
        $oldCollection = $reflectionProperty->getValue($object);
22
23
        $newCollection = $oldCollection->map(
24
            function ($item) use ($objectCopier) {
25
                return $objectCopier($item);
26
            }
27
        );
28
29
        $reflectionProperty->setValue($object, $newCollection);
30
    }
31
}
32