Passed
Pull Request — develop (#97)
by BENARD
12:42
created

UpdateYoutubeData   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VideoGamesRecords\CoreBundle\Scheduler\Handler;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use VideoGamesRecords\CoreBundle\Entity\Video;
9
use VideoGamesRecords\CoreBundle\Handler\Video\YoutubeDataHandler;
10
use VideoGamesRecords\CoreBundle\Scheduler\Message\UpdatePlayerChartRanking;
11
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
12
use VideoGamesRecords\CoreBundle\ValueObject\VideoType;
13
14
#[AsMessageHandler]
15
class UpdateYoutubeData
16
{
17
    public function __construct(
18
        private readonly EntityManagerInterface $em,
19
        private readonly YoutubeDataHandler $handler
20
    ) {
21
    }
22
23
    public function __invoke(UpdatePlayerChartRanking $message): void
24
    {
25
        $videos = $this->em->getRepository(Video::class)->findBy(
26
            [
27
                'isActive' => true,
28
                'type' => VideoType::YOUTUBE
29
            ],
30
            ['id' => 'DESC'],
31
            $message->getNb()
32
        );
33
        /** @var Video $video */
34
        foreach ($videos as $video) {
35
            $this->handler->process($video);
36
        }
37
    }
38
}
39