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

ListCommand::executeAsync()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 2
eloc 10
nc 2
nop 2
1
<?php
2
3
namespace Padawan\Command;
4
5
use Padawan\Domain\Core\Project;
6
use Padawan\Domain\ProjectRepository;
7
use Padawan\Domain\Core\Node\ClassData;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Padawan\Framework\Application\Socket\SocketOutput;
11
12
/**
13
 * Class ListCommand
14
 */
15
class ListCommand extends AsyncCommand
16
{
17
    protected function configure()
18
    {
19
        $this->setName("list")
20
            ->setDescription("Shows all classes with filepath")
21
            ->addArgument(
22
                "path",
23
                InputArgument::REQUIRED,
24
                "Path to the project root"
25
            );
26
    }
27
    protected function executeAsync(InputInterface $input, SocketOutput $output)
28
    {
29
        $path = $input->getArgument("path");
30
31
        $projectRepository = $this->getContainer()->get(ProjectRepository::class);
32
        /** @var Project */
33
        $project = $projectRepository->findByPath($path);
34
        $classesList = [];
35
        foreach ($project->getIndex()->getClasses() as $class) {
36
            $classesList[] = [
37
                'fqcn' => $class->fqcn->toString(),
38
                'filepath' => $class->file
39
            ];
40
        }
41
        yield $output->write(json_encode($classesList));
42
    }
43
}
44