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

GenerateCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
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