Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
LogJournalSubscriber
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getSubscribedEvents
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 saveLogJournal
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace App\Domain\Reporting\Symfony\EventSubscriber\Kernel;
4
5use App\Domain\Reporting\Dictionary\LogJournalActionDictionary;
6use App\Domain\Reporting\Symfony\EventSubscriber\Event\LogJournalEvent;
7use App\Infrastructure\ORM\Reporting\Repository\LogJournal;
8use Doctrine\ORM\EntityManagerInterface;
9use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
11class LogJournalSubscriber implements EventSubscriberInterface
12{
13    /**
14     * @var EntityManagerInterface
15     */
16    private $entityManager;
17
18    /**
19     * @var \App\Domain\Reporting\Repository\LogJournal
20     */
21    private $logJournalRepository;
22
23    public function __construct(EntityManagerInterface $entityManager, LogJournal $logJournalRepository)
24    {
25        $this->entityManager        = $entityManager;
26        $this->logJournalRepository = $logJournalRepository;
27    }
28
29    public static function getSubscribedEvents()
30    {
31        return [
32            LogJournalEvent::class => ['saveLogJournal'],
33        ];
34    }
35
36    public function saveLogJournal(LogJournalEvent $event)
37    {
38        $logJournal = $event->getLogJournal();
39        $this->entityManager->persist($logJournal);
40        $this->entityManager->flush();
41
42        if (LogJournalActionDictionary::DELETE === $logJournal->getAction()) {
43            $this->logJournalRepository->updateDeletedLog($event->getSubject());
44        }
45    }
46}