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\Processors; |
7
|
|
|
|
8
|
|
|
use PhUml\Code\ClassDefinition; |
9
|
|
|
use PhUml\Code\Codebase; |
10
|
|
|
use PhUml\Code\EnumDefinition; |
11
|
|
|
use PhUml\Code\InterfaceDefinition; |
12
|
|
|
use PhUml\Code\TraitDefinition; |
13
|
|
|
use PhUml\Graphviz\Builders\ClassGraphBuilder; |
14
|
|
|
use PhUml\Graphviz\Builders\EnumGraphBuilder; |
15
|
|
|
use PhUml\Graphviz\Builders\InterfaceGraphBuilder; |
16
|
|
|
use PhUml\Graphviz\Builders\TraitGraphBuilder; |
17
|
|
|
use PhUml\Graphviz\Digraph; |
18
|
|
|
use PhUml\Graphviz\DigraphPrinter; |
19
|
|
|
use PhUml\Templates\TemplateEngine; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* It creates a digraph from a `Codebase` and returns it as a string in DOT format |
23
|
|
|
*/ |
24
|
|
|
final class GraphvizProcessor implements Processor |
25
|
|
|
{ |
26
|
18 |
|
public static function fromConfiguration(GraphvizConfiguration $configuration): GraphvizProcessor |
27
|
|
|
{ |
28
|
18 |
|
$style = $configuration->digraphStyle(); |
29
|
18 |
|
$associationsBuilder = $configuration->edgesBuilder(); |
30
|
|
|
|
31
|
18 |
|
return new GraphvizProcessor( |
32
|
18 |
|
new ClassGraphBuilder($associationsBuilder), |
33
|
18 |
|
new InterfaceGraphBuilder(), |
34
|
18 |
|
new TraitGraphBuilder(), |
35
|
18 |
|
new EnumGraphBuilder(), |
36
|
18 |
|
new DigraphPrinter(new TemplateEngine(), $style) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
18 |
|
private function __construct( |
41
|
|
|
private readonly ClassGraphBuilder $classBuilder, |
42
|
|
|
private readonly InterfaceGraphBuilder $interfaceBuilder, |
43
|
|
|
private readonly TraitGraphBuilder $traitBuilder, |
44
|
|
|
private readonly EnumGraphBuilder $enumBuilder, |
45
|
|
|
private readonly DigraphPrinter $printer |
46
|
|
|
) { |
47
|
|
|
} |
48
|
|
|
|
49
|
11 |
|
public function name(): string |
50
|
|
|
{ |
51
|
11 |
|
return 'Graphviz'; |
52
|
|
|
} |
53
|
|
|
|
54
|
13 |
|
public function process(Codebase $codebase): OutputContent |
55
|
|
|
{ |
56
|
13 |
|
$digraph = new Digraph(); |
57
|
|
|
/** @var ClassDefinition|InterfaceDefinition|TraitDefinition|EnumDefinition $definition */ |
58
|
13 |
|
foreach ($codebase->definitions() as $definition) { |
59
|
11 |
|
$this->extractElements($definition, $codebase, $digraph); |
60
|
|
|
} |
61
|
13 |
|
return new OutputContent($this->printer->toDot($digraph)); |
62
|
|
|
} |
63
|
|
|
|
64
|
11 |
|
private function extractElements( |
65
|
|
|
ClassDefinition|InterfaceDefinition|TraitDefinition|EnumDefinition $definition, |
66
|
|
|
Codebase $codebase, |
67
|
|
|
Digraph $digraph |
68
|
|
|
): void { |
69
|
11 |
|
match ($definition::class) { |
70
|
11 |
|
ClassDefinition::class => $digraph->add($this->classBuilder->extractFrom($definition, $codebase)), |
|
|
|
|
71
|
11 |
|
InterfaceDefinition::class => $digraph->add($this->interfaceBuilder->extractFrom($definition, $codebase)), |
|
|
|
|
72
|
11 |
|
TraitDefinition::class => $digraph->add($this->traitBuilder->extractFrom($definition, $codebase)), |
|
|
|
|
73
|
11 |
|
default => $digraph->add($this->enumBuilder->extractFrom($definition, $codebase)), |
|
|
|
|
74
|
|
|
}; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.