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

DoctrineCollectionFilter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 15 1
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