Passed
Push — v2 ( c4de3c...f057b3 )
by Brice
03:43
created

RestoreTasks::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.6511

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 7
cts 12
cp 0.5833
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 2
crap 3.6511
1
<?php
2
3
namespace JobQueue\Application\Console;
4
5
use JobQueue\Application\Utils\CommandTrait;
6
use JobQueue\Infrastructure\ServiceContainer;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\Console\Question\ConfirmationQuestion;
12
13
final class RestoreTasks extends Command
14
{
15
    use CommandTrait;
16
17
    public function configure()
18
    {
19
        $this
20
            ->setName('restore')
21
            ->setDescription('Sets all tasks to "waiting" status (useful after a crash)')
22
            ->addOption('force', 'y', InputOption::VALUE_NONE, 'Skip validation')
23
        ;
24
    }
25
26
    /**
27
     *
28
     * @param InputInterface $input
29
     * @param OutputInterface $output
30
     * @return int
31
     */
32 1
    protected function execute(InputInterface $input, OutputInterface $output): int
33
    {
34 1
        if (!$input->getOption('force')) {
35
            $helper = $this->getHelper('question'); /** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */
36
            $question = new ConfirmationQuestion('Do you want to set all tasks to "waiting" status? (y/f) ', false);
37
            if (!$helper->ask($input, $output, $question)) {
38
                $output->writeln('Canceled');
39
                return 0;
40
            }
41
        }
42
43 1
        ServiceContainer::getInstance()
44 1
            ->queue
45 1
            ->restore();
46
47 1
        $this->formatInfoSection('Queue restored', $output);
48
49 1
        return 0;
50
    }
51
}
52