TaskCreateCommand   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A configure() 0 11 2
A execute() 0 17 3
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
17
/**
18
 * Class TaskCreateCommand
19
 *
20
 * @category None
21
 * @package  Cli\CliBundle\Command
22
 * @author   Martin Pham <[email protected]>
23
 * @license  None http://
24
 * @link     None
25
 */
26
class TaskCreateCommand extends ContainerAwareCommand
27
{
28
    /**
29
     * TaskCommand
30
     *
31
     * @var Command
32
     */
33
    protected $taskCommand;
34
35
    /**
36
     * TaskListCommand constructor
37
     *
38
     * @param Command $taskCommand Task Command
39
     *
40
     * @throws LogicException
41
     */
42
    public function __construct(Command $taskCommand)
43
    {
44
        $this->taskCommand = $taskCommand;
45
46
        try {
47
            parent::__construct();
48
        } catch (LogicException $e) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\Console\Exception\LogicException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file 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.

Loading history...
49
            throw $e;
50
        }
51
    }
52
53
    /**
54
     * Configure
55
     *
56
     * @return void
57
     * @throws InvalidArgumentException
58
     */
59
    protected function configure()
60
    {
61
        try {
62
            $this
63
                ->setName('task:create')
64
                ->setDescription('...')
65
                ->addArgument('name', InputArgument::REQUIRED, 'Task name');
66
        } catch (InvalidArgumentException $e) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\Consol...nvalidArgumentException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file 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.

Loading history...
67
            // no catch exception
68
        }
69
    }
70
71
    /**
72
     * Execute
73
     *
74
     * @param InputInterface  $input
75
     * @param OutputInterface $output
76
     *
77
     * @return void
78
     * @throws TaskNameIsEmptyException
79
     * @throws TaskNameIsAlreadyExistedException
80
     * @throws TaskCannotBeSavedException
81
     * @throws InvalidArgumentException
82
     */
83
    protected function execute(InputInterface $input, OutputInterface $output)
84
    {
85
        try {
86
            $name = $input->getArgument('name');
87
        } catch (InvalidArgumentException $e) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\Consol...nvalidArgumentException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file 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.

Loading history...
88
            throw $e;
89
        }
90
91
        try {
92
            $task = $this->taskCommand->addNewTask($name);
93
94
            $output->writeln('Task created with #' . $task->getId());
95
        } catch (TaskNameIsEmptyException | TaskNameIsAlreadyExistedException | TaskCannotBeSavedException $e) {
96
            throw $e;
97
        }
98
99
    }
100
101
}
102