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; ...@@ -11,9 +11,9 @@ use Irstea\PlantUmlBundle\Finder\ClassFinder;
use Irstea\PlantUmlBundle\Finder\FilteringFinder; use Irstea\PlantUmlBundle\Finder\FilteringFinder;
use Irstea\PlantUmlBundle\Model\ClassVisitor; use Irstea\PlantUmlBundle\Model\ClassVisitor;
use Irstea\PlantUmlBundle\Model\Graph; use Irstea\PlantUmlBundle\Model\Graph;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Reference;
/** /**
...@@ -49,12 +49,13 @@ class GraphDefinitionBuilder ...@@ -49,12 +49,13 @@ class GraphDefinitionBuilder
/** /**
* @var Definition * @var Definition
*/ */
private $definition = null; private $definition;
/** /**
* @param ContainerBuilder $container * @param ContainerBuilder $container
* @param string $baseId * @param string $baseId
* @param array $config * @param array $config
* @param ClassFilterBuilder $filterBuilder
*/ */
public function __construct(ContainerBuilder $container, $baseId, array $config, ClassFilterBuilder $filterBuilder) public function __construct(ContainerBuilder $container, $baseId, array $config, ClassFilterBuilder $filterBuilder)
{ {
...@@ -70,7 +71,7 @@ class GraphDefinitionBuilder ...@@ -70,7 +71,7 @@ class GraphDefinitionBuilder
/** /**
* @return Definition * @return Definition
*/ */
public function build() public function build(): Definition
{ {
if (!$this->definition) { if (!$this->definition) {
return $this->definition = $this->doBuild(); return $this->definition = $this->doBuild();
...@@ -82,9 +83,9 @@ class GraphDefinitionBuilder ...@@ -82,9 +83,9 @@ class GraphDefinitionBuilder
/** /**
* @return Definition * @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; $layoutFilter = $this->filterBuilder->build($this->config['layout']) ?: $sourceFilter;
$decorator = $this->buildFilteredDecorator(); $decorator = $this->buildFilteredDecorator();
...@@ -96,9 +97,9 @@ class GraphDefinitionBuilder ...@@ -96,9 +97,9 @@ class GraphDefinitionBuilder
} }
/** /**
* @return Refernce[] * @return Reference[]
*/ */
protected function buildSources() protected function buildSources(): array
{ {
$finder = $this->buildFinder(); $finder = $this->buildFinder();
$filter = $this->filterBuilder->build($this->config['sources']); $filter = $this->filterBuilder->build($this->config['sources']);
...@@ -115,7 +116,7 @@ class GraphDefinitionBuilder ...@@ -115,7 +116,7 @@ class GraphDefinitionBuilder
/** /**
* @return Reference * @return Reference
*/ */
protected function buildFinder() protected function buildFinder(): Reference
{ {
$config = $this->config['sources']; $config = $this->config['sources'];
...@@ -125,12 +126,14 @@ class GraphDefinitionBuilder ...@@ -125,12 +126,14 @@ class GraphDefinitionBuilder
case 'classes': case 'classes':
return $this->setDefinition('finder.classes', ClassFinder::class, $config['directories']); return $this->setDefinition('finder.classes', ClassFinder::class, $config['directories']);
} }
throw new \InvalidArgumentException("Invalid source type: {$config['type']}");
} }
/** /**
* @return Reference * @return Reference
*/ */
protected function buildFilteredDecorator() protected function buildFilteredDecorator(): Reference
{ {
$decorator = $this->buildDecorator(); $decorator = $this->buildDecorator();
if (!$decorator) { if (!$decorator) {
...@@ -148,7 +151,7 @@ class GraphDefinitionBuilder ...@@ -148,7 +151,7 @@ class GraphDefinitionBuilder
/** /**
* @return Reference * @return Reference
*/ */
protected function buildDecorator() protected function buildDecorator(): Reference
{ {
$config = $this->config['decoration']['decorators']; $config = $this->config['decoration']['decorators'];
...@@ -156,7 +159,7 @@ class GraphDefinitionBuilder ...@@ -156,7 +159,7 @@ class GraphDefinitionBuilder
return null; return null;
} }
if (count($config) === 1) { if (\count($config) === 1) {
return $this->buildTypedDecorator($config[0]); return $this->buildTypedDecorator($config[0]);
} }
...@@ -177,9 +180,9 @@ class GraphDefinitionBuilder ...@@ -177,9 +180,9 @@ class GraphDefinitionBuilder
* *
* @return Reference * @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( return $this->setDefinitionDecorator(
"decorator.$type", "decorator.$type",
"irstea.plant_uml.decorator.$type.template", "irstea.plant_uml.decorator.$type.template",
...@@ -193,7 +196,7 @@ class GraphDefinitionBuilder ...@@ -193,7 +196,7 @@ class GraphDefinitionBuilder
/** /**
* @return Reference * @return Reference
*/ */
protected function buildNamespace() protected function buildNamespace(): Reference
{ {
$type = $this->config['layout']['namespaces']; $type = $this->config['layout']['namespaces'];
...@@ -218,7 +221,7 @@ class GraphDefinitionBuilder ...@@ -218,7 +221,7 @@ class GraphDefinitionBuilder
* *
* @return Reference * @return Reference
*/ */
protected function setDefinition($localId, $classOrDef, ...$arguments) protected function setDefinition($localId, $classOrDef, ...$arguments): Reference
{ {
if ($classOrDef instanceof Definition) { if ($classOrDef instanceof Definition) {
$definition = $classOrDef; $definition = $classOrDef;
...@@ -238,9 +241,9 @@ class GraphDefinitionBuilder ...@@ -238,9 +241,9 @@ class GraphDefinitionBuilder
* *
* @return Reference * @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); $def->setArguments($arguments);
return $this->setDefinition($localId, $def); return $this->setDefinition($localId, $def);
...@@ -251,7 +254,7 @@ class GraphDefinitionBuilder ...@@ -251,7 +254,7 @@ class GraphDefinitionBuilder
* *
* @return string * @return string
*/ */
protected function globalId($localId) protected function globalId($localId): string
{ {
return "{$this->baseId}.$localId"; 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