StartCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Dock\Cli;
4
5
use Dock\Docker\Compose\Project;
6
use Dock\Project\ProjectException;
7
use Dock\Project\ProjectManager;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\ArrayInput;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class StartCommand extends Command
14
{
15
    /**
16
     * @var ProjectManager
17
     */
18
    private $projectManager;
19
    /**
20
     * @var Project
21
     */
22
    private $project;
23
24
    /**
25
     * @param ProjectManager $projectManager
26
     * @param Project        $project
27
     */
28
    public function __construct(ProjectManager $projectManager, Project $project)
29
    {
30
        parent::__construct();
31
32
        $this->projectManager = $projectManager;
33
        $this->project = $project;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    protected function configure()
40
    {
41
        $this
42
            ->setName('start')
43
            ->setDescription('Start the project')
44
        ;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    protected function execute(InputInterface $input, OutputInterface $output)
51
    {
52
        try {
53
            $this->projectManager->start($this->project);
54
        } catch (ProjectException $e) {
55
            $output->writeln('<error>'.$e->getMessage().'</error>');
56
57
            return 1;
58
        }
59
60
        return $this->getApplication()->run(
61
            new ArrayInput(['command' => 'ps']),
62
            $output
63
        );
64
    }
65
}
66