ModelFactoryCollectionCompilerPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 8 3
1
<?php
2
3
namespace Xsolve\ModelFactoryBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class ModelFactoryCollectionCompilerPass implements CompilerPassInterface
10
{
11
    const TAG_NAME = 'xsolve.model_factory_bundle.model_factory';
12
    const ATTRIBUTE_NAME_MODEL_FACTORY_COLLECTION_SERVICE_ID = 'model-factory-collection-id';
13
14
    /**
15
     * @param ContainerBuilder $container
16
     */
17
    public function process(ContainerBuilder $container)
18
    {
19
        $modelFactoryServiceIdToTags = $container->findTaggedServiceIds(self::TAG_NAME);
20
        foreach ($modelFactoryServiceIdToTags as $modelFactoryServiceId => $tags) {
21
            foreach ($tags as $tag) {
22
                $container
23
                    ->getDefinition($tag[self::ATTRIBUTE_NAME_MODEL_FACTORY_COLLECTION_SERVICE_ID])
24
                    ->addMethodCall('addModelFactory', [new Reference($modelFactoryServiceId)]);
25
            }
26
        }
27
    }
28
}
29