AmqpCacheWarmer   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 48
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isOptional() 0 4 1
A warmUp() 0 5 1
A loadServices() 0 10 3
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