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

ReleaseDateNotifications   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 5
dl 0
loc 40
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

3 Methods

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