AddSeasonSubscriber   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 26
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 6 1
A onFlush() 0 16 3
1
<?php
2
3
namespace App\EventListener;
4
5
use App\Entity\PerformanceEvent;
6
use App\Entity\RepertoireSeason;
7
use App\Repository\RepertoireSeasonRepository;
8
use Doctrine\Common\EventSubscriber;
9
use Doctrine\ORM\Event\OnFlushEventArgs;
10
use Doctrine\ORM\Events;
11
12
class AddSeasonSubscriber implements EventSubscriber
13
{
14 48
    public function getSubscribedEvents()
15
    {
16
        return [
17 48
            Events::onFlush
18
        ];
19
    }
20
21 12
    public function onFlush(OnFlushEventArgs $args)
22
    {
23 12
        $em = $args->getEntityManager();
24 12
        $uow = $em->getUnitOfWork();
25
26 12
        foreach ($uow->getScheduledEntityInsertions() as $keyEntity => $entity) {
27 2
            if ($entity instanceof PerformanceEvent) {
28 1
                $performance = $entity->getPerformance();
29 1
                $currentSeason = $em->getRepository(RepertoireSeason::class)
30 1
                    ->findSeasonByDate($entity->getDateTime());
31 1
                $performance->addSeason($currentSeason);
32 1
                $classMetadata = $em->getClassMetadata(get_class($performance));
33 1
                $uow->computeChangeSet($classMetadata, $performance);
34
            }
35
        }
36 12
    }
37
}
38