These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminBundle\Helper; |
||
4 | |||
5 | use Doctrine\ORM\EntityManager; |
||
6 | use Kunstmaan\AdminBundle\Event\DeepCloneAndSaveEvent; |
||
7 | use Kunstmaan\AdminBundle\Event\Events; |
||
8 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
||
9 | |||
10 | /** |
||
11 | * This helper will help you to clone Entities |
||
12 | */ |
||
13 | class CloneHelper |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @var EntityManager |
||
18 | */ |
||
19 | private $em; |
||
20 | |||
21 | /** |
||
22 | * @var EventDispatcherInterface |
||
23 | */ |
||
24 | private $eventDispatcher; |
||
25 | |||
26 | /** |
||
27 | * @param EntityManager $em The EntityManager |
||
28 | * @param EventDispatcherInterface $eventDispatcher The EventDispatchInterface |
||
29 | */ |
||
30 | public function __construct(EntityManager $em, EventDispatcherInterface $eventDispatcher) |
||
31 | { |
||
32 | $this->em = $em; |
||
33 | $this->eventDispatcher = $eventDispatcher; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @param mixed $entity |
||
38 | * |
||
39 | * @return mixed |
||
0 ignored issues
–
show
|
|||
40 | */ |
||
41 | public function deepCloneAndSave($entity) |
||
42 | { |
||
43 | $clonedEntity = clone $entity; |
||
44 | $this->eventDispatcher->dispatch(Events::DEEP_CLONE_AND_SAVE, new DeepCloneAndSaveEvent($entity, $clonedEntity, $this->em)); |
||
45 | |||
46 | $this->em->persist($clonedEntity); |
||
47 | $this->em->flush(); |
||
48 | |||
49 | $this->eventDispatcher->dispatch(Events::POST_DEEP_CLONE_AND_SAVE, new DeepCloneAndSaveEvent($entity, $clonedEntity, $this->em)); |
||
50 | |||
51 | return $clonedEntity; |
||
52 | } |
||
53 | |||
54 | } |
||
55 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.