Completed
Pull Request — master (#29)
by Aleh
02:59
created

ListCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 1
A execute() 0 17 2
1
<?php
2
3
namespace Padawan\Command;
4
5
use Padawan\Domain\ProjectRepository;
6
use Padawan\Domain\Core\Project;
7
use Padawan\Domain\Core\Node\ClassData;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Output\OutputInterface;
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 execute(InputInterface $input, OutputInterface $output)
28
    {
29
        $path = $input->getArgument("path");
30
        $container = $this->getContainer();
0 ignored issues
show
Unused Code introduced by
$container 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...
31
32
        $projectRepository = $this->getContainer()->get(ProjectRepository::class);
33
        /** @var Project */
34
        $project = $projectRepository->findByPath($path);
35
        $classesList = [];
36
        foreach ($project->getIndex()->getClasses() as $class) {
37
            $classesList[] = [
38
                'fqcn' => $class->fqcn->toString(),
39
                'filepath' => $class->file
40
            ];
41
        }
42
        yield $output->write(json_encode($classesList));
43
    }
44
}
45