Passed
Pull Request — master (#22)
by Luis
24:40 queued 21:48
created

ClassDiagramGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 32
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0
wmc 3
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.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\Generators;
9
10
use League\Pipeline\Pipeline;
11
use PhUml\Console\Commands\GeneratorInput;
12
use PhUml\Processors\OutputContent;
13
use PhUml\Stages\CreateClassDiagram;
14
use PhUml\Stages\CreateDigraph;
15
use PhUml\Stages\FindCode;
16
use PhUml\Stages\ParseCode;
17
use PhUml\Stages\SaveFile;
18
19
/**
20
 * It generates a UML class diagram from a directory with PHP code
21
 *
22
 * The image produced is a `.png` that will be saved in a specified path
23
 */
24
final class ClassDiagramGenerator
25
{
26 7
    public static function fromConfiguration(ClassDiagramConfiguration $configuration): ClassDiagramGenerator
27
    {
28 7
        return new self(
29 7
            new FindCode($configuration->codeFinder(), $configuration->display()),
30 7
            new ParseCode($configuration->codeParser(), $configuration->display()),
31 7
            new CreateDigraph($configuration->graphvizProcessor(), $configuration->display()),
32 7
            new CreateClassDiagram($configuration->imageProcessor(), $configuration->display()),
33 7
            new SaveFile($configuration->writer(), $configuration->display()),
34
        );
35
    }
36
37 7
    private function __construct(
38
        private readonly FindCode $findCode,
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 38 at column 25
Loading history...
39
        private readonly ParseCode $parseCode,
40
        private readonly CreateDigraph $createDigraph,
41
        private readonly CreateClassDiagram $createClassDiagram,
42
        private readonly SaveFile $saveFile,
43
    ) {
44
    }
45
46 6
    public function generate(GeneratorInput $input): void
47
    {
48 6
        $pipeline = (new Pipeline())
49 6
            ->pipe($this->findCode)
50 6
            ->pipe($this->parseCode)
51 6
            ->pipe($this->createDigraph)
52 6
            ->pipe($this->createClassDiagram)
53 6
            ->pipe(fn (OutputContent $content) => $this->saveFile->saveTo($content, $input->filePath()));
54
55 6
        $pipeline->process($input->codebaseDirectory());
56
    }
57
}
58