Passed
Push — union-types ( b56600 )
by Luis
14:03
created

DigraphGenerator::generate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 7.4
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\Generators;
9
10
use League\Pipeline\Pipeline;
0 ignored issues
show
Bug introduced by
The type League\Pipeline\Pipeline was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use PhUml\Console\Commands\GeneratorInput;
12
use PhUml\Parser\CodeFinder;
13
use PhUml\Parser\CodeParser;
14
use PhUml\Processors\GraphvizProcessor;
15
use PhUml\Processors\OutputWriter;
16
use PhUml\Stages\CreateDigraph;
17
use PhUml\Stages\FindCode;
18
use PhUml\Stages\ParseCode;
19
use PhUml\Stages\SaveFile;
20
21
/**
22
 * It generates a file with a digraph in DOT format that can be used to create a class diagram
23
 *
24
 * You might want to create a different output using either `neato` or `dot`.
25
 * The file this command creates can be used as an intermediate step.
26
 * For instance:
27
 *
28
 * `neato -Tpdf output.gv > output.pdf`
29
 *
30
 * Where `output.gv` is the file generated by this action
31
 */
32
final class DigraphGenerator
33
{
34
    private CodeFinder $codeFinder;
35
36
    private CodeParser $codeParser;
37
38
    protected GraphvizProcessor $digraphProcessor;
39
40
    private OutputWriter $writer;
41
42
    public static function fromConfiguration(DigraphConfiguration $configuration): DigraphGenerator
43
    {
44
        return new self(
45
            $configuration->codeFinder(),
46
            $configuration->codeParser(),
47
            $configuration->graphvizProcessor(),
48
            $configuration->writer()
49
        );
50
    }
51
52
    public function __construct(
53
        CodeFinder  $codeFinder,
54
        CodeParser $codeParser,
55
        GraphvizProcessor $digraphProcessor,
56
        OutputWriter $writer
57
    ) {
58
        $this->codeFinder = $codeFinder;
59
        $this->codeParser = $codeParser;
60
        $this->digraphProcessor = $digraphProcessor;
61
        $this->writer = $writer;
62
    }
63
64
    public function generate(GeneratorInput $input): void
65
    {
66
        $pipeline = (new Pipeline())
67
            ->pipe(new FindCode($this->codeFinder, $input->display()))
68
            ->pipe(new ParseCode($this->codeParser, $input->display()))
69
            ->pipe(new CreateDigraph($this->digraphProcessor, $input->display()))
70
            ->pipe(new SaveFile($this->writer, $input->outputFile(), $input->display()));
71
72
        $pipeline->process($input->directory());
73
    }
74
}
75