Passed
Push — develop ( 6aacf8...6c0b7f )
by BENARD
11:52
created

YoutubeDataUpdate::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace VideoGamesRecords\CoreBundle\Command\Video;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use VideoGamesRecords\CoreBundle\Handler\Video\YoutubeDataHandler;
10
use VideoGamesRecords\CoreBundle\Entity\Video;
11
use VideoGamesRecords\CoreBundle\ValueObject\VideoType;
12
13
class YoutubeDataUpdate extends Command
14
{
15
    protected static $defaultName = 'vgr-core:video-youtube-data-update';
16
17
    private EntityManagerInterface $em;
18
    private YoutubeDataHandler $youtubeDataHandler;
19
20
    public function __construct(EntityManagerInterface $em, YoutubeDataHandler $youtubeDataHandler)
21
    {
22
        $this->em = $em;
23
        $this->youtubeDataHandler = $youtubeDataHandler;
24
        parent::__construct();
25
    }
26
27
    protected function configure(): void
28
    {
29
        $this
30
            ->setName('vgr-core:video-youtube-data-update')
31
            ->setDescription('Command to update videos with youtube data');
32
        parent::configure();
33
    }
34
35
    /**
36
     * @param InputInterface  $input
37
     * @param OutputInterface $output
38
     * @return int
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output): int
41
    {
42
        $videos = $this->em->getRepository(Video::class)->findBy(['isActive' => true, 'type' => VideoType::TYPE_YOUTUBE, 'title' => null]);
43
        /** @var Video $video */
44
        foreach ($videos as $video) {
45
            $this->youtubeDataHandler->process($video);
46
        }
47
48
        return Command::SUCCESS;
49
    }
50
}
51