Completed
Push — master ( 79f8b3...655236 )
by Tomas
02:58 queued 11s
created

FactoryValidatorPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 8 4
A addFactoryServiceId() 0 4 1
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 36
    public function process(ContainerBuilder $container)
32
    {
33 36
        foreach (self::$factoryServiceIds as $id) {
34 3
            if (!$container->hasAlias($id) && !$container->hasDefinition($id)) {
35 1
                throw new ServiceNotFoundException(sprintf('Factory with ID "%s" could not be found', $id));
36
            }
37
        }
38 35
    }
39
40
    /**
41
     * @param mixed $factoryServiceIds
42
     */
43 3
    public static function addFactoryServiceId($factoryServiceIds)
44
    {
45 3
        self::$factoryServiceIds[] = $factoryServiceIds;
46 3
    }
47
}
48