Completed
Push — master ( 9d1ab7...13f027 )
by Luis
04:13 queued 02:19
created

GenerateDotFileCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 48
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 33
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 35
nc 1
nop 0
dl 0
loc 48
ccs 33
cts 33
cp 1
crap 1
rs 9.125
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Console\Commands;
9
10
use PhUml\Configuration\DigraphConfiguration;
11
use PhUml\Configuration\DotFileBuilder;
12
use PhUml\Parser\CodebaseDirectory;
13
use Symfony\Component\Console\Input\InputArgument;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * This command will generate file in `DOT` format that is ready to use to generate a UML class
20
 * diagram using either `neato` or `dot`
21
 *
22
 * This command has 2 required arguments
23
 *
24
 * 1. `directory`. The path where your codebase lives
25
 * 2. `output`. The path to where the generated `gv` file will be saved
26
 *
27
 * There are 2 options
28
 *
29
 * 1. `recursive`. If present it will look recursively within the `directory` provided
30
 * 2. `associations`. If present the command will generate associations to the classes/interfaces
31
 *    injected through the constructor and the attributes of the class
32
 */
33
class GenerateDotFileCommand extends GeneratorCommand
34
{
35 45
    protected function configure()
36
    {
37
        $this
38 45
            ->setName('phuml:dot')
39 45
            ->setDescription('Generates a digraph in DOT format of a given directory')
40 45
            ->setHelp(
41
                <<<HELP
42 45
Example:
43
    php bin/phuml phuml:dot -r -a ./src dot.gv
44
45
    This example will scan the `./src` directory recursively for php files.
46
    It will process them with the option `associations` set to true.
47
    It will generate a digraph in dot format and save it to the file `dot.gv`.
48
HELP
49
            )
50 45
            ->addArgument(
51 45
                'directory',
52 45
                InputArgument::REQUIRED,
53 45
                'The directory to be scanned to generate the dot file'
54
            )
55 45
            ->addArgument(
56 45
                'output',
57 45
                InputArgument::REQUIRED,
58 45
                'The file name for your dot file'
59
            )
60 45
            ->addOption(
61 45
                'recursive',
62 45
                'r',
63 45
                InputOption::VALUE_NONE,
64 45
                'Look for classes in the given directory recursively'
65
            )
66 45
            ->addOption(
67 45
                'associations',
68 45
                'a',
69 45
                InputOption::VALUE_NONE,
70 45
                'If present, the Graphviz processor will generate association among classes'
71
            )
72 45
            ->addOption(
73 45
                'hide-private',
74 45
                'i',
75 45
                InputOption::VALUE_NONE,
76 45
                'If present, no private attributes or methods will be processed'
77
            )
78 45
            ->addOption(
79 45
                'hide-protected',
80 45
                'o',
81 45
                InputOption::VALUE_NONE,
82 45
                'If present, no protected attributes or methods will be processed'
83
            )
84
        ;
85 45
    }
86
87 12
    protected function execute(InputInterface $input, OutputInterface $output)
88
    {
89 12
        $codebasePath = $input->getArgument('directory');
90 12
        $dotFilePath = $input->getArgument('output');
91
92 12
        $builder = new DotFileBuilder(new DigraphConfiguration($input->getOptions()));
93
94 12
        $dotFileGenerator = $builder->dotFileGenerator();
95 12
        $dotFileGenerator->attach($this->display);
96
97 12
        $codeFinder = $builder->codeFinder();
98 12
        $codeFinder->addDirectory(CodebaseDirectory::from($codebasePath));
99
100 9
        $dotFileGenerator->generate($codeFinder, $dotFilePath);
101
102 9
        return 0;
103
    }
104
}
105