Passed
Push — dependabot/npm_and_yarn/microm... ( f2f212...f35bf2 )
by
unknown
13:36 queued 05:58
created

SendNotificationsCommand::execute()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 14
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 24
rs 9.7998
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Command;
8
9
use Chamilo\CoreBundle\Framework\Container;
10
use Database;
11
use Doctrine\ORM\EntityManager;
12
use Notification;
13
use Symfony\Component\Console\Command\Command;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
use Symfony\Component\Console\Style\SymfonyStyle;
18
19
class SendNotificationsCommand extends Command
20
{
21
    protected static $defaultName = 'app:send-notifications';
22
23
    public function __construct(
24
        private readonly EntityManager $em
25
    ) {
26
        parent::__construct();
27
    }
28
29
    protected function configure(): void
30
    {
31
        $this
32
            ->setDescription('Send notifications')
33
            ->addOption('debug', null, InputOption::VALUE_NONE, 'Enable debug mode')
34
            ->setHelp('This command sends notifications using the Notification class.');
35
    }
36
37
    protected function execute(InputInterface $input, OutputInterface $output): int
38
    {
39
        Database::setManager($this->em);
40
41
        $container = $this->getApplication()->getKernel()->getContainer();
42
        Container::setContainer($container);
43
44
        $io = new SymfonyStyle($input, $output);
45
        $debug = $input->getOption('debug');
46
47
        if ($debug) {
48
            error_log('Debug mode activated');
49
            $io->note('Debug mode activated');
50
        }
51
52
        $notification = new Notification();
53
        $notification->send();
54
55
        if ($debug) {
56
            error_log('Notifications have been sent.');
57
            $io->success('Notifications have been sent successfully.');
58
        }
59
60
        return Command::SUCCESS;
61
    }
62
}
63