Total Complexity | 6 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
13 | class plNodeLabelBuilder |
||
14 | { |
||
15 | /** @var TemplateEngine */ |
||
16 | private $engine; |
||
17 | |||
18 | /** @var plGraphvizProcessorStyle */ |
||
19 | private $style; |
||
20 | |||
21 | public function __construct(TemplateEngine $engine, plGraphvizProcessorStyle $style) |
||
22 | { |
||
23 | $this->engine = $engine; |
||
24 | $this->style = $style; |
||
25 | } |
||
26 | |||
27 | public function labelForClass(plPhpClass $class): string |
||
28 | { |
||
29 | return $this->buildLabel('class.html.twig', [ |
||
30 | 'class' => $class, |
||
31 | 'style' => $this->style, |
||
32 | ]); |
||
33 | } |
||
34 | |||
35 | public function labelForInterface(plPhpInterface $interface): string |
||
36 | { |
||
37 | return $this->buildLabel('interface.html.twig', [ |
||
38 | 'interface' => $interface, |
||
39 | 'style' => $this->style, |
||
40 | ]); |
||
41 | } |
||
42 | |||
43 | private function buildLabel(string $template, array $options): string |
||
44 | { |
||
45 | try { |
||
46 | return "<{$this->removeNewLinesFrom($this->engine->render($template, $options))}>"; |
||
47 | } catch (LoaderError | RuntimeError | SyntaxError $e) { |
||
48 | throw new plNodeLabelError($e); |
||
49 | } |
||
50 | } |
||
51 | |||
52 | private function removeNewLinesFrom(string $label): string |
||
55 | } |
||
56 | } |
||
57 |