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

ScheduleRunCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
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