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

VideoRecommendationCacheSubscriber::postRemove()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
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