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

ListCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 1
A executeAsync() 0 16 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