Passed
Pull Request — master (#30)
by
unknown
46:28 queued 21:27
created

DigraphGenerator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 4
dl 0
loc 6
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Generators;
7
8
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...
9
use PhUml\Console\Commands\GeneratorInput;
10
use PhUml\Processors\OutputContent;
11
use PhUml\Stages\CreateDigraph;
12
use PhUml\Stages\FindCode;
13
use PhUml\Stages\ParseCode;
14
use PhUml\Stages\SaveFile;
15
16
/**
17
 * It generates a file with a digraph in DOT format that can be used to create a class diagram
18
 *
19
 * You might want to create a different output using either `neato` or `dot`.
20
 * The file this command creates can be used as an intermediate step.
21
 * For instance:
22
 *
23
 * `neato -Tpdf output.gv > output.pdf`
24
 *
25
 * Where `output.gv` is the file generated by this action
26
 */
27
final class DigraphGenerator
28
{
29 4
    public static function fromConfiguration(DigraphConfiguration $configuration): DigraphGenerator
30
    {
31 4
        return new self(
32 4
            new FindCode($configuration->codeFinder(), $configuration->display()),
33 4
            new ParseCode($configuration->codeParser(), $configuration->display()),
34 4
            new CreateDigraph($configuration->graphvizProcessor(), $configuration->display()),
35 4
            new SaveFile($configuration->writer(), $configuration->display()),
36
        );
37
    }
38
39 4
    private function __construct(
40
        private readonly FindCode $findCode,
41
        private readonly ParseCode $parseCode,
42
        private readonly CreateDigraph $createDigraph,
43
        private readonly SaveFile $saveFile,
44
    ) {
45
    }
46
47 3
    public function generate(GeneratorInput $input): void
48
    {
49 3
        $pipeline = (new Pipeline())
50 3
            ->pipe($this->findCode)
51 3
            ->pipe($this->parseCode)
52 3
            ->pipe($this->createDigraph)
53 3
            ->pipe(fn (OutputContent $content) => $this->saveFile->saveTo($content, $input->filePath()));
54
55 3
        $pipeline->process($input->codebaseDirectory());
56
    }
57
}
58