for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* PHP version 7.1
*
* This source file is subject to the license that is bundled with this package in the file LICENSE.
*/
use Twig_Environment as TemplateEngine;
use Twig_Error_Loader as LoaderError;
use Twig_Error_Runtime as RuntimeError;
use Twig_Error_Syntax as SyntaxError;
class plNodeLabelBuilder
{
/** @var TemplateEngine */
private $engine;
/** @var plGraphvizProcessorStyle */
private $style;
public function __construct(TemplateEngine $engine, plGraphvizProcessorStyle $style)
$this->engine = $engine;
$this->style = $style;
}
public function labelForClass(plPhpClass $class): string
return $this->buildLabel('class.html.twig', [
'class' => $class,
'style' => $this->style,
]);
public function labelForInterface(plPhpInterface $interface): string
return $this->buildLabel('interface.html.twig', [
'interface' => $interface,
private function buildLabel(string $template, array $options): string
try {
return "<{$this->removeNewLinesFrom($this->engine->render($template, $options))}>";
} catch (LoaderError | RuntimeError | SyntaxError $e) {
throw new plNodeLabelError($e);
private function removeNewLinesFrom(string $label): string
return trim(preg_replace('/\s\s+|\n/', '', $label));