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

YoutubeDataUpdate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 0
f 0
dl 0
loc 36
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 9 2
A __construct() 0 5 1
A configure() 0 6 1
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