AmqpCacheWarmer::isOptional()   A
last analyzed

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 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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