RestoreTasks::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.125

Importance

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