AmqpCacheWarmer::loadServices()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 12
1
<?php
2
3
namespace TreeHouse\QueueBundle\CacheWarmer;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
7
8
class AmqpCacheWarmer implements CacheWarmerInterface
9
{
10
    /**
11
     * @var ContainerInterface
12
     */
13
    private $container;
14
15
    /**
16
     * @param ContainerInterface $container
17
     */
18
    public function __construct(ContainerInterface $container)
19
    {
20
        $this->container = $container;
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26
    public function isOptional()
27
    {
28
        return true;
29
    }
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function warmUp($cacheDir)
35
    {
36
        $this->loadServices($this->container->getParameter('tree_house.queue.exchanges'));
37
        $this->loadServices($this->container->getParameter('tree_house.queue.queues'));
38
    }
39
40
    /**
41
     * Loads the services from the DIC, thereby automatically declaring associated exchanges/queues.
42
     *
43
     * @param string[] $services
44
     */
45
    private function loadServices($services)
46
    {
47
        foreach ($services as $service) {
48
            if (false === $service['auto_declare']) {
49
                continue;
50
            }
51
52
            $this->container->get($service['id']);
53
        }
54
    }
55
}
56