Test Failed
Push — master ( faf208...51c6fd )
by Martin
14:25
created

TaskListCommand::execute()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 29
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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