RestoreTasks   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 35
ccs 5
cts 15
cp 0.3333
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A execute() 0 16 3
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