Completed
Push — master ( a7de57...5589b2 )
by Tobias
05:33
created

FactoryValidatorPass::addFactoryServiceId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the BazingaGeocoderBundle package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Bazinga\GeocoderBundle\DependencyInjection\Compiler;
14
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
18
19
/**
20
 * Make sure that the factory actually exists
21
 *
22
 * @author Tobias Nyholm <[email protected]>
23
 */
24
class FactoryValidatorPass implements CompilerPassInterface
25
{
26
    private static $factoryServiceIds = [];
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 24
    public function process(ContainerBuilder $container)
32
    {
33 24
        foreach (self::$factoryServiceIds as $id) {
34
            if (!$container->hasAlias($id) && !$container->hasDefinition($id)) {
35
                throw new ServiceNotFoundException(sprintf('Factory with ID "%s" could not be found', $id));
36
            }
37
        }
38 24
    }
39
40
    /**
41
     * @param mixed $factoryServiceIds
42
     */
43
    public static function addFactoryServiceId($factoryServiceIds)
44
    {
45
        self::$factoryServiceIds[] = $factoryServiceIds;
46
    }
47
}
48