Test Failed
Push — develop ( 7c3d28...e1debf )
by BENARD
12:55 queued 06:18
created

VideoRecommendationCacheSubscriber   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A postRemove() 0 6 2
A postUpdate() 0 6 2
A __construct() 0 3 1
A getSubscribedEvents() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\EventSubscriber;
6
7
use Doctrine\Common\EventSubscriber;
8
use Doctrine\ORM\Events;
9
use Doctrine\Persistence\Event\LifecycleEventArgs;
10
use VideoGamesRecords\CoreBundle\Entity\Video;
11
use VideoGamesRecords\CoreBundle\Service\VideoRecommendationService;
12
13
class VideoRecommendationCacheSubscriber implements EventSubscriber
14
{
15
    public function __construct(
16
        private readonly VideoRecommendationService $videoRecommendationService
17
    ) {
18
    }
19
20
    public function getSubscribedEvents(): array
21
    {
22
        return [
23
            Events::postUpdate,
24
            Events::postRemove,
25
        ];
26
    }
27
28
    public function postUpdate(LifecycleEventArgs $args): void
29
    {
30
        $entity = $args->getObject();
31
32
        if ($entity instanceof Video) {
33
            $this->videoRecommendationService->clearVideoRecommendationsCache($entity);
34
        }
35
    }
36
37
    public function postRemove(LifecycleEventArgs $args): void
38
    {
39
        $entity = $args->getObject();
40
41
        if ($entity instanceof Video) {
42
            $this->videoRecommendationService->clearVideoRecommendationsCache($entity);
43
        }
44
    }
45
}
46