Completed
Push — dev ( 240328...12a618 )
by
unknown
20:20
created

EntityCloner   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 57
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A handleRelation() 0 8 2
A afterClone() 0 6 1
A getObjectManager() 0 4 1
1
<?php
2
/**
3
 * @year    2016
4
 * @link    https://github.com/nnx-framework/cloner
5
 * @author  Lobanov Aleksandr <[email protected]>
6
 */
7
8
namespace Nnx\Cloner;
9
10
use Doctrine\Common\Collections\ArrayCollection;
11
use Doctrine\Common\Persistence\ObjectManager;
12
13
/**
14
 * Class EntityCloner
15
 *
16
 * @package Nnx\Cloner
17
 */
18
class EntityCloner extends Cloner
19
{
20
    /**
21
     * @var ObjectManager
22
     */
23
    private $objectManager;
24
25
    /**
26
     * EntityCloner constructor.
27
     *
28
     * @param ClonerInterface       $clonerManager
29
     * @param Options\ClonerOptions $options
30
     * @param ObjectManager         $objectManager
31
     */
32
    public function __construct(
33
        ClonerInterface $clonerManager,
34
        Options\ClonerOptions $options,
35
        ObjectManager $objectManager
0 ignored issues
show
Unused Code introduced by
The parameter $objectManager is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    ) {
37
        parent::__construct($clonerManager, $options);
38
    }
39
40
    /**
41
     * @param mixed                          $object
42
     * @param string                         $relationName
43
     * @param Options\Cloner\RelationOptions $options
44
     *
45
     * @return ArrayCollection|mixed
46
     */
47
    protected function handleRelation($object, $relationName, Options\Cloner\RelationOptions $options)
48
    {
49
        $cloneData = parent::handleRelation($object, $relationName, $options);
50
        if (is_array($cloneData)) {
51
            return new ArrayCollection($cloneData);
52
        }
53
        return $cloneData;
54
    }
55
56
    /**
57
     * @param mixed $object
58
     * @param mixed $cloneObject
59
     */
60
    protected function afterClone($object, $cloneObject)
61
    {
62
        parent::afterClone($object, $cloneObject);
63
64
        $this->getObjectManager()->detach($cloneObject);
65
    }
66
67
    /**
68
     * @return ObjectManager
69
     */
70
    protected function getObjectManager()
71
    {
72
        return $this->objectManager;
73
    }
74
}
75