|
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 = []; |
|
|
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.