Completed
Push — master ( 14cbb2...16a771 )
by MoshiMoshi
02:26
created

CacheWarmerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
3
/*
4
 * This file is part of the ConfigCacheBundle package.
5
 *
6
 * Copyright (c) 2015 Yahoo Japan Corporation
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace YahooJapan\ConfigCacheBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
use YahooJapan\ConfigCacheBundle\ConfigCache\ConfigCache;
18
19
/**
20
 * Adds ConfigCache service ids to the ConfigCacheListener property for warming up caches.
21
 */
22
class CacheWarmerPass implements CompilerPassInterface
23
{
24
    protected $warmerId = 'yahoo_japan_config_cache.cache_warmer';
25
26
    /**
27
     * {@inheritdoc}
28
     *
29
     * @SuppressWarnings(PHPMD.UnusedLocalVariable)
30
     */
31 11
    public function process(ContainerBuilder $container)
32
    {
33 11
        if (!$container->hasDefinition($this->warmerId)) {
34 1
            return;
35
        }
36 10
        $definition = $container->getDefinition($this->warmerId);
37
38 10
        foreach ($container->findTaggedServiceIds(ConfigCache::TAG_CACHE_WARMER) as $configId => $attributes) {
39 10
            $definition->addMethodCall('addConfig', array(new Reference($configId)));
40 10
        }
41 10
    }
42
}
43