ListCommand::executeAsync()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 2
1
<?php
2
3
namespace Padawan\Command;
4
5
use Padawan\Domain\Project;
6
use Padawan\Domain\ProjectRepository;
7
use Padawan\Domain\Project\Node\ClassData;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Padawan\Framework\Application\Socket\HttpOutput;
11
use Padawan\Framework\Utils\PathResolver;
12
13
/**
14
 * Class ListCommand
15
 */
16
class ListCommand extends AsyncCommand
17
{
18
    protected function configure()
19
    {
20
        $this->setName("list")
21
            ->setDescription("Shows all classes with filepath")
22
            ->addArgument(
23
                "path",
24
                InputArgument::REQUIRED,
25
                "Path to the project root"
26
            );
27
    }
28
    protected function executeAsync(InputInterface $input, HttpOutput $output)
29
    {
30
        $path = $input->getArgument("path");
31
32
        $projectRepository = $this->getContainer()->get(ProjectRepository::class);
33
        /** @var PathResolver */
34
        $pathResolver = $this->getContainer()->get(PathResolver::class);
35
        /** @var Project */
36
        $project = $projectRepository->findByPath($path);
37
        $classesList = [];
0 ignored issues
show
Unused Code introduced by
$classesList is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
38
        $dto = function ($class) use ($path, $pathResolver) {
39
            return [
40
                'fqcn' => $class->fqcn->toString(),
41
                'filepath' => $pathResolver->join([$path, $class->file])
42
            ];
43
        };
44
        $classesList = array_values(
45
            array_merge(
46
                array_map($dto, $project->getIndex()->getClasses()),
47
                array_map($dto, $project->getIndex()->getInterfaces())
48
            )
49
        );
50
        yield $output->write(json_encode($classesList));
51
    }
52
}
53