Passed
Push — master ( b74a1f...762e12 )
by MoshiMoshi
03:10
created

RestorableCachePass::process()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 9.2
cc 4
eloc 8
nc 3
nop 1
crap 4
1
<?php
2
3
/*
4
 * This file is part of the ConfigCacheBundle package.
5
 *
6
 * Copyright (c) 2015-2016 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\RestorablePhpFileCache;
18
19
/**
20
 * RestorableCachePass is a service register pass to recreate the caches.
21
 */
22
class RestorableCachePass implements CompilerPassInterface
23
{
24
    protected $restorerId = 'yahoo_japan_config_cache.cache_restorer';
25
    protected $saverId    = 'yahoo_japan_config_cache.cache_saver';
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 13
    public function process(ContainerBuilder $container)
31
    {
32 13
        if (!$container->hasDefinition($this->restorerId) || !$container->hasDefinition($this->saverId)) {
33 2
            return;
34
        }
35 11
        $restorer = $container->getDefinition($this->restorerId);
36 11
        $saver    = $container->getDefinition($this->saverId);
37
38 11
        foreach ($container->findTaggedServiceIds(RestorablePhpFileCache::TAG_RESTORABLE_CACHE) as $configCacheId => $attributes) {
39 1
            $restorer->addMethodCall('addConfig', array(new Reference($configCacheId)));
40 1
            $saver->addMethodCall('addConfig', array(new Reference($configCacheId)));
41 11
        }
42 11
    }
43
}
44