Completed
Push — master ( c5110b...a167e6 )
by Valentyn
13:46
created

ReleaseDateNotifications::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 11
cp 0
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace App\Movies\Command;
4
5
use App\Movies\DTO\ReleaseDateNotificationDTO;
6
use App\Movies\Repository\MovieReleaseDateRepository;
7
use App\Users\Service\SendEmailService;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class ReleaseDateNotifications extends Command
13
{
14
    /** @var $repository MovieReleaseDateRepository */
15
    private $repository;
16
17
    /** @var $emailService SendEmailService */
18
    private $emailService;
19
20
    public function __construct(MovieReleaseDateRepository $repository, SendEmailService $emailService, ?string $name = null)
21
    {
22
        parent::__construct($name);
23
24
        $this->repository = $repository;
25
        $this->emailService = $emailService;
26
    }
27
28
    protected function configure()
29
    {
30
        $this
31
            ->setName('app:release-date-notifications')
32
            ->setDescription('Send release date notifications if any movies released today')
33
            ->setHelp('This command will notify users about release dates');
34
    }
35
36
    protected function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        $date = date('Y-m-d');
39
        $rows = $this->repository->findAllByDate($date);
40
        $rows = $rows->getScalarResult();
41
42
        foreach ($rows as $row) {
43
            $dto = new ReleaseDateNotificationDTO(
44
                (int) $row['m_id'],
45
                $row['m_original_title'],
46
                $row['c_name']
47
            );
48
            $this->emailService->sendReleaseDateNotification($row['u_email'], $dto);
49
        }
50
    }
51
}
52