|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace 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 TaskUpdateCommand |
|
20
|
|
|
* |
|
21
|
|
|
* @category None |
|
22
|
|
|
* @package Cli\CliBundle\Command |
|
23
|
|
|
* @author Martin Pham <[email protected]> |
|
24
|
|
|
* @license None http:// |
|
25
|
|
|
* @link None |
|
26
|
|
|
*/ |
|
27
|
|
|
class TaskUpdateCommand 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:update') |
|
65
|
|
|
->setDescription('...') |
|
66
|
|
|
->addArgument('id', InputArgument::REQUIRED, 'Task ID') |
|
67
|
|
|
->addArgument('name', InputArgument::REQUIRED, 'Task name') |
|
68
|
|
|
->addArgument('status', InputArgument::REQUIRED, 'Task status'); |
|
69
|
|
|
} catch (InvalidArgumentException $e) { |
|
|
|
|
|
|
70
|
|
|
// no catch exception |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Execute |
|
76
|
|
|
* |
|
77
|
|
|
* @param InputInterface $input |
|
78
|
|
|
* @param OutputInterface $output |
|
79
|
|
|
* |
|
80
|
|
|
* @return void |
|
81
|
|
|
* @throws TaskNameIsEmptyException |
|
82
|
|
|
* @throws TaskNameIsAlreadyExistedException |
|
83
|
|
|
* @throws TaskCannotBeSavedException |
|
84
|
|
|
* @throws TaskNotFoundException |
|
85
|
|
|
* @throws InvalidArgumentException |
|
86
|
|
|
*/ |
|
87
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
88
|
|
|
{ |
|
89
|
|
|
try { |
|
90
|
|
|
$taskId = $input->getArgument('id'); |
|
91
|
|
|
$name = $input->getArgument('name'); |
|
92
|
|
|
$status = $input->getArgument('status'); |
|
93
|
|
|
} catch (InvalidArgumentException $e) { |
|
|
|
|
|
|
94
|
|
|
throw $e; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
try { |
|
98
|
|
|
$this->taskCommand->editTask( |
|
99
|
|
|
$taskId, |
|
100
|
|
|
[ |
|
101
|
|
|
'name' => $name, |
|
102
|
|
|
'status' => $status |
|
103
|
|
|
] |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
$output->writeln('Task is updated'); |
|
107
|
|
|
} catch (TaskNotFoundException | TaskNameIsEmptyException | TaskNameIsAlreadyExistedException | TaskCannotBeSavedException $e) { |
|
108
|
|
|
throw $e; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.