FactoryValidatorPass::addFactoryServiceId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace DH\NavigationBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
8
9
/**
10
 * Make sure that the factory actually exists.
11
 */
12
class FactoryValidatorPass implements CompilerPassInterface
13
{
14
    private static $factoryServiceIds = [];
15
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function process(ContainerBuilder $container): void
20
    {
21
        foreach (self::$factoryServiceIds as $id) {
22
            if (!$container->hasAlias($id) && !$container->hasDefinition($id)) {
23
                throw new ServiceNotFoundException(sprintf('Factory with ID "%s" could not be found', $id));
24
            }
25
        }
26
    }
27
28
    public static function addFactoryServiceId(string $factoryServiceIds): void
29
    {
30
        self::$factoryServiceIds[] = $factoryServiceIds;
31
    }
32
}
33