1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flagbit\Plantuml\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
|
10
|
|
|
class WriteCommand extends Command |
11
|
|
|
{ |
12
|
11 |
|
protected function configure() |
13
|
|
|
{ |
14
|
11 |
|
$this |
15
|
11 |
|
->setName('write') |
16
|
11 |
|
->setDescription('Generates PlantUML diagram from php source') |
17
|
11 |
|
->addArgument( |
18
|
11 |
|
'files', |
19
|
|
|
InputArgument::IS_ARRAY |
20
|
11 |
|
) |
21
|
11 |
|
->addOption('without-constants', null, null, 'Disables rendering of constants') |
22
|
11 |
|
->addOption('without-methods', null, null, 'Disables rendering of methods') |
23
|
11 |
|
->addOption('without-properties', null, null, 'Disables rendering of properties') |
24
|
11 |
|
->addOption('without-doc-content', null, null, 'Disables parsing doc block for methods or properties') |
25
|
11 |
|
->addOption('grouping', null, null, 'Enable deprecated and todo grouping for methods') |
26
|
11 |
|
->addOption('without-function-params', null, null, 'Do not display function param, only count'); |
27
|
11 |
|
} |
28
|
|
|
|
29
|
11 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
30
|
|
|
{ |
31
|
11 |
|
$broker = new \TokenReflection\Broker(new \TokenReflection\Broker\Backend\Memory()); |
32
|
|
|
|
33
|
11 |
|
foreach ($input->getArgument('files') as $fileToProcess) { |
34
|
11 |
|
if (is_dir($fileToProcess)) { |
35
|
|
|
$broker->processDirectory($fileToProcess); |
36
|
|
|
} |
37
|
|
|
else { |
38
|
11 |
|
$broker->processFile($fileToProcess); |
39
|
|
|
} |
40
|
11 |
|
} |
41
|
|
|
|
42
|
11 |
|
$writerOptions = new \Flagbit\Plantuml\TokenReflection\WriterOptions(); |
|
|
|
|
43
|
|
|
|
44
|
11 |
|
$classWriter = new \Flagbit\Plantuml\TokenReflection\ClassWriter(); |
45
|
11 |
|
if (!$input->getOption('without-constants')) { |
46
|
11 |
|
$classWriter->setConstantWriter(new \Flagbit\Plantuml\TokenReflection\ConstantWriter()); |
47
|
11 |
|
} |
48
|
11 |
|
if (!$input->getOption('without-properties')) { |
49
|
11 |
|
if ($input->getOption('grouping')) { |
50
|
1 |
|
$classWriter->setPropertyWriter(new \Flagbit\Plantuml\TokenReflection\PropertyGroupingWriter()); |
51
|
1 |
|
} else { |
52
|
10 |
|
$classWriter->setPropertyWriter(new \Flagbit\Plantuml\TokenReflection\PropertyWriter()); |
53
|
|
|
} |
54
|
11 |
|
} |
55
|
11 |
|
if (!$input->getOption('without-methods')) { |
56
|
11 |
|
if ($input->getOption('grouping')) { |
57
|
1 |
|
$classWriter->setMethodWriter(new \Flagbit\Plantuml\TokenReflection\MethodGroupingWriter()); |
58
|
1 |
|
} else { |
59
|
10 |
|
$classWriter->setMethodWriter(new \Flagbit\Plantuml\TokenReflection\MethodWriter()); |
60
|
|
|
} |
61
|
11 |
|
} |
62
|
11 |
|
if (!$input->getOption('without-doc-content')) { |
63
|
11 |
|
$classWriter->setDocContentWriter(new \Flagbit\Plantuml\TokenReflection\DocContentWriter()); |
64
|
11 |
|
} |
65
|
|
|
|
66
|
11 |
|
$output->write('@startuml', "\n"); |
|
|
|
|
67
|
11 |
|
foreach ($broker->getClasses() as $class) { |
68
|
|
|
/** @var $class \TokenReflection\IReflectionClass */ |
69
|
11 |
|
$output->write($classWriter->writeElement($class)); |
70
|
11 |
|
} |
71
|
11 |
|
$output->write('@enduml', "\n"); |
|
|
|
|
72
|
11 |
|
} |
73
|
|
|
} |
74
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.