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

FlushTasks::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
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 FlushTasks extends Command
14
{
15
    use CommandTrait;
16
17
    public function configure()
18
    {
19
        $this
20
            ->setName('flush')
21
            ->setDescription('Deletes all tasks from the queue')
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 delete all tasks from the queue? (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
            ->flush();
46
47 1
        $this->formatInfoSection('Queue flushed', $output);
48
49 1
        return 0;
50
    }
51
}
52