Passed
Push — master ( b67a30...b7883b )
by Kevin
09:53 queued 08:10
created

ScheduleRunCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 5 1
A execute() 0 7 2
1
<?php
2
3
namespace Zenstruck\ScheduleBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Console\Style\SymfonyStyle;
9
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
10
use Zenstruck\ScheduleBundle\EventListener\ConsoleOutputScheduleSubscriber;
11
use Zenstruck\ScheduleBundle\Schedule\ScheduleRunner;
12
13
/**
14
 * @author Kevin Bond <[email protected]>
15
 */
16
final class ScheduleRunCommand extends Command
17
{
18
    protected static $defaultName = 'schedule:run';
19
20
    private $scheduleRunner;
21
    private $dispatcher;
22
23 9
    public function __construct(ScheduleRunner $scheduleRunner, EventDispatcherInterface $dispatcher)
24
    {
25 9
        $this->scheduleRunner = $scheduleRunner;
26 9
        $this->dispatcher = $dispatcher;
27
28 9
        parent::__construct();
29 9
    }
30
31 9
    protected function configure(): void
32
    {
33
        $this
34 9
            ->setDescription('Runs scheduled tasks that are due')
35 9
            ->setHelp(<<<EOF
36 9
Exit code 0: no tasks ran, schedule skipped or all tasks run were successful.
37
Exit code 1: some of the tasks ran failed.
38
EOF
39
        )
40
        ;
41 9
    }
42
43 9
    protected function execute(InputInterface $input, OutputInterface $output): int
44
    {
45 9
        $io = new SymfonyStyle($input, $output);
46
47 9
        $this->dispatcher->addSubscriber(new ConsoleOutputScheduleSubscriber($io));
48
49 9
        return ($this->scheduleRunner)()->isSuccessful() ? 0 : 1;
50
    }
51
}
52