Completed
Push — master ( 81db43...f030be )
by Aleh
12s
created

UpdateCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
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\Domain\Generator\IndexGenerator;
8
use Padawan\Framework\Domain\Project\Persister;
9
use Padawan\Framework\Domain\Project\InMemoryIndex;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Padawan\Framework\Application\Socket\SocketOutput;
13
14
class UpdateCommand extends AsyncCommand
15
{
16
    protected function configure()
17
    {
18
        $this->setName("update")
19
            ->setDescription("Updates index for the project")
20
            ->addArgument(
21
                "path",
22
                InputArgument::REQUIRED,
23
                "Path to the project root. Default: current directory"
24
            );
25
    }
26
    protected function executeAsync(InputInterface $input, SocketOutput $output)
27
    {
28
        $path = $input->getArgument("path");
29
30
        $projectRepository = $this->getContainer()->get(ProjectRepository::class);
31
        $project = $projectRepository->findByPath($path);
32
        $generator = $this->getContainer()->get(IndexGenerator::class);
33
34
        $generator->generateProjectIndex($project, false);
35
        $persister = $this->getContainer()->get(Persister::class);
36
37
        yield $output->disconnect();
38
        yield $persister->save($project);
39
    }
40
}
41