Commit 7ec074f4 authored by Guillaume Perréal's avatar Guillaume Perréal

DefinitionDecorator => ChildDefinition.

parent d56eec09
......@@ -11,9 +11,9 @@ use Irstea\PlantUmlBundle\Finder\ClassFinder;
use Irstea\PlantUmlBundle\Finder\FilteringFinder;
use Irstea\PlantUmlBundle\Model\ClassVisitor;
use Irstea\PlantUmlBundle\Model\Graph;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference;
/**
......@@ -49,12 +49,13 @@ class GraphDefinitionBuilder
/**
* @var Definition
*/
private $definition = null;
private $definition;
/**
* @param ContainerBuilder $container
* @param string $baseId
* @param array $config
* @param ContainerBuilder $container
* @param string $baseId
* @param array $config
* @param ClassFilterBuilder $filterBuilder
*/
public function __construct(ContainerBuilder $container, $baseId, array $config, ClassFilterBuilder $filterBuilder)
{
......@@ -70,7 +71,7 @@ class GraphDefinitionBuilder
/**
* @return Definition
*/
public function build()
public function build(): Definition
{
if (!$this->definition) {
return $this->definition = $this->doBuild();
......@@ -82,9 +83,9 @@ class GraphDefinitionBuilder
/**
* @return Definition
*/
protected function doBuild()
protected function doBuild(): Definition
{
list($source, $sourceFilter) = $this->buildSources();
[$source, $sourceFilter] = $this->buildSources();
$layoutFilter = $this->filterBuilder->build($this->config['layout']) ?: $sourceFilter;
$decorator = $this->buildFilteredDecorator();
......@@ -96,9 +97,9 @@ class GraphDefinitionBuilder
}
/**
* @return Refernce[]
* @return Reference[]
*/
protected function buildSources()
protected function buildSources(): array
{
$finder = $this->buildFinder();
$filter = $this->filterBuilder->build($this->config['sources']);
......@@ -115,7 +116,7 @@ class GraphDefinitionBuilder
/**
* @return Reference
*/
protected function buildFinder()
protected function buildFinder(): Reference
{
$config = $this->config['sources'];
......@@ -125,12 +126,14 @@ class GraphDefinitionBuilder
case 'classes':
return $this->setDefinition('finder.classes', ClassFinder::class, $config['directories']);
}
throw new \InvalidArgumentException("Invalid source type: {$config['type']}");
}
/**
* @return Reference
*/
protected function buildFilteredDecorator()
protected function buildFilteredDecorator(): Reference
{
$decorator = $this->buildDecorator();
if (!$decorator) {
......@@ -148,7 +151,7 @@ class GraphDefinitionBuilder
/**
* @return Reference
*/
protected function buildDecorator()
protected function buildDecorator(): Reference
{
$config = $this->config['decoration']['decorators'];
......@@ -156,7 +159,7 @@ class GraphDefinitionBuilder
return null;
}
if (count($config) === 1) {
if (\count($config) === 1) {
return $this->buildTypedDecorator($config[0]);
}
......@@ -177,9 +180,9 @@ class GraphDefinitionBuilder
*
* @return Reference
*/
protected function buildTypedDecorator($type)
protected function buildTypedDecorator($type): Reference
{
if (in_array($type, ['entity', 'associations', 'fields'])) {
if (\in_array($type, ['entity', 'associations', 'fields'], true)) {
return $this->setDefinitionDecorator(
"decorator.$type",
"irstea.plant_uml.decorator.$type.template",
......@@ -193,7 +196,7 @@ class GraphDefinitionBuilder
/**
* @return Reference
*/
protected function buildNamespace()
protected function buildNamespace(): Reference
{
$type = $this->config['layout']['namespaces'];
......@@ -218,7 +221,7 @@ class GraphDefinitionBuilder
*
* @return Reference
*/
protected function setDefinition($localId, $classOrDef, ...$arguments)
protected function setDefinition($localId, $classOrDef, ...$arguments): Reference
{
if ($classOrDef instanceof Definition) {
$definition = $classOrDef;
......@@ -238,9 +241,9 @@ class GraphDefinitionBuilder
*
* @return Reference
*/
protected function setDefinitionDecorator($localId, $templateId, ...$arguments)
protected function setDefinitionDecorator($localId, $templateId, ...$arguments): Reference
{
$def = new DefinitionDecorator($templateId);
$def = new ChildDefinition($templateId);
$def->setArguments($arguments);
return $this->setDefinition($localId, $def);
......@@ -251,7 +254,7 @@ class GraphDefinitionBuilder
*
* @return string
*/
protected function globalId($localId)
protected function globalId($localId): string
{
return "{$this->baseId}.$localId";
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment