Passed
Push — develop ( 605aab...b17d99 )
by Stone
06:54 queued 11s
created

AbstractAppSubscriber::flush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\EventSubscriber;
4
5
use App\Event\AbstractAppEvent;
6
use App\FlashMessage\AddFlashTrait;
7
use Doctrine\ORM\EntityManagerInterface;
8
9
abstract class AbstractAppSubscriber
10
{
11
    use AddFlashTrait;
12
13
    /**
14
     * @var EntityManagerInterface
15
     */
16
    protected $em;
17
18
    /**
19
     * @return array The event names to listen to
20
     */
21
    abstract public static function getSubscribedEvents();
22
23
    /**
24
     * @param AbstractAppEvent $event
25
     * Registers the trick into the database
26
     */
27
    public function sendToDatabase(AbstractAppEvent $event)
28
    {
29
        $entity = $event->getEntity();
30
        $this->em->persist($entity);
31
        $this->em->flush();
32
    }
33
34
    public function deleteFromDatabase(AbstractAppEvent $event)
35
    {
36
        $entity = $event->getEntity();
37
        $this->em->remove($entity);
38
        $this->em->flush();
39
    }
40
41
    public function persist(AbstractAppEvent $event)
42
    {
43
        $entity = $event->getEntity();
44
        $this->em->persist($entity);
45
    }
46
47
    public function flush()
48
    {
49
        $this->em->flush();
50
    }
51
52
    /**
53
     * @required
54
     * @param EntityManagerInterface $em
55
     */
56
    public function setEm(EntityManagerInterface $em): void
57
    {
58
        $this->em = $em;
59
    }
60
}