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