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

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