Passed
Push — master ( e91424...06fcec )
by Martin
06:44
created

TaskListCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 81
rs 10
c 0
b 0
f 0

3 Methods

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