Passed
Push — 5.0 ( d46d5f )
by Luis
39s queued 12s
created

ClassDiagramGenerator::generateClassDiagram()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.0
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\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 45
    public static function fromConfiguration(ClassDiagramConfiguration $configuration): ClassDiagramGenerator
27
    {
28
        return new self(
29
            new FindCode($configuration->codeFinder(), $configuration->display()),
30
            new ParseCode($configuration->codeParser(), $configuration->display()),
31 45
            new CreateDigraph($configuration->graphvizProcessor(), $configuration->display()),
32 45
            new CreateClassDiagram($configuration->imageProcessor(), $configuration->display()),
33 45
            new SaveFile($configuration->writer(), $configuration->display()),
34
        );
35
    }
36
37
    private function __construct(
38
        private FindCode $findCode,
39
        private ParseCode $parseCode,
40
        private CreateDigraph $createDigraph,
41
        private CreateClassDiagram $createClassDiagram,
42
        private SaveFile $saveFile,
43
    ) {
44
    }
45 45
46
    public function generate(GeneratorInput $input): void
47 45
    {
48 39
        $pipeline = (new Pipeline())
49 39
            ->pipe($this->findCode)
50 39
            ->pipe($this->parseCode)
51
            ->pipe($this->createDigraph)
52
            ->pipe($this->createClassDiagram)
53 39
            ->pipe(fn (OutputContent $content) => $this->saveFile->saveTo($content, $input->filePath()));
54
55 39
        $pipeline->process($input->codebaseDirectory());
56 39
    }
57
}
58