Completed
Push — master ( 5bda77...cb2c73 )
by Aleh
10s
created

GenerateCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 0
cbo 5
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 1
A execute() 0 23 3
1
<?php
2
3
namespace Padawan\Command;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Padawan\Domain\Core\Project;
9
use Padawan\Domain\Core\Index;
10
use Padawan\Domain\Generator\IndexGenerator;
11
use Padawan\Framework\Project\Persister;
12
13
class GenerateCommand extends CliCommand
14
{
15
    protected function configure()
16
    {
17
        $this->setName("generate")
18
            ->setDescription("Generates new index for the project")
19
            ->addArgument(
20
                "path",
21
                InputArgument::OPTIONAL,
22
                "Path to the project root. Default: current directory"
23
            );
24
    }
25
    protected function execute(InputInterface $input, OutputInterface $output)
26
    {
27
        $rootDir = $input->getArgument("path");
28
        if (empty($rootDir)) {
29
            $rootDir = getcwd();
30
        }
31
        try {
32
            $generator = $this->get(IndexGenerator::class);
33
34
            $project = new Project(
35
                $this->get(Index::class),
36
                $rootDir
37
            );
38
39
            $generator->generateIndex($project);
40
            $persister = $this->get(Persister::class);
41
42
            $persister->save($project);
43
            $output->writeln("<info>Index generated</info>");
44
        } catch (\Exception $e) {
45
            $output->writeln(sprintf("<error>Error: %s</error>", $e->getMessage()));
46
        }
47
    }
48
}
49