Completed
Push — master ( f030be...9a1100 )
by Aleh
12s
created

GenerateCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 0
cbo 4
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 1
A execute() 0 18 2
1
<?php
2
3
namespace Padawan\Command;
4
5
use Padawan\Domain\Project;
6
use Padawan\Domain\ProjectRepository;
7
use Padawan\Framework\Utils\PathResolver;
8
use Padawan\Domain\Generator\IndexGenerator;
9
use Padawan\Framework\Domain\Project\Persister;
10
use Padawan\Framework\Domain\Project\InMemoryIndex;
11
use Symfony\Component\Console\Input\InputArgument;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
class GenerateCommand extends CliCommand
16
{
17
    protected function configure()
18
    {
19
        $this->setName("generate")
20
            ->setDescription("Generates new index for the project")
21
            ->addArgument(
22
                "path",
23
                InputArgument::OPTIONAL,
24
                "Path to the project root. Default: current directory"
25
            );
26
    }
27
    protected function execute(InputInterface $input, OutputInterface $output)
28
    {
29
        $path = $input->getArgument("path");
30
        /** @var PathResolver $pathResolver */
31
        $pathResolver = $this->getContainer()->get(PathResolver::class);
32
        if (empty($path)) {
33
            $path = $pathResolver->getWorkingDirectory();
34
        }
35
36
        $projectRepository = $this->getContainer()->get(ProjectRepository::class);
37
        $project = $projectRepository->findByPath($path);
38
        $generator = $this->getContainer()->get(IndexGenerator::class);
39
40
        $generator->generateProjectIndex($project);
41
        $persister = $this->getContainer()->get(Persister::class);
42
43
        $persister->save($project);
44
    }
45
}
46