Passed
Push — master ( 8e4ec1...86ac2d )
by Martin
02:35
created

TaskCleanCommand::configure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
namespace Todo\Cli\CliBundle\Command;
4
5
use Symfony\Component\Console\Exception\InvalidArgumentException;
6
use Todo\Application\Task\Command;
7
use Todo\Application\Task\Exception\TaskCannotBeRemovedException;
8
use Todo\Domain\Task;
9
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10
use Symfony\Component\Console\Exception\LogicException;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
/**
15
 * Class TaskCleanCommand
16
 *
17
 * @category None
18
 * @package  Todo\Cli\CliBundle\Command
19
 * @author   Martin Pham <[email protected]>
20
 * @license  None http://
21
 * @link     None
22
 */
23
class TaskCleanCommand extends ContainerAwareCommand
24
{
25
    /**
26
     * TaskCommand
27
     *
28
     * @var Command
29
     */
30
    protected $taskCommand;
31
32
    /**
33
     * TaskListCommand constructor
34
     *
35
     * @param Command $taskCommand Task Command
36
     *
37
     * @throws LogicException
38
     */
39
    public function __construct(Command $taskCommand)
40
    {
41
        $this->taskCommand = $taskCommand;
42
43
        try {
44
            parent::__construct();
45
        } catch (LogicException $e) {
46
            throw $e;
47
        }
48
    }
49
50
51
    /**
52
     * Configure
53
     *
54
     * @return void
55
     */
56
    protected function configure()
57
    {
58
        try {
59
            $this
60
                ->setName('task:clean')
61
                ->setDescription('...');
62
        } catch (InvalidArgumentException $e) {
63
            // no catch exception
64
        }
65
    }
66
67
    /**
68
     * Execute
69
     *
70
     * @param InputInterface  $input  Input
71
     * @param OutputInterface $output Output
72
     *
73
     * @return void
74
     * @throws LogicException
75
     * @throws TaskCannotBeRemovedException
76
     */
77
    protected function execute(InputInterface $input, OutputInterface $output)
78
    {
79
        try {
80
            parent::execute($input, $output);
81
        } catch (LogicException $e) {
82
            // no catch
83
        }
84
85
        try {
86
            $this->taskCommand->cleanAllCompletedTasks();
87
        } catch (TaskCannotBeRemovedException $e) {
88
            throw $e;
89
        }
90
91
92
        $output->writeln('Cleaned');
93
    }
94
95
}
96