JobCompilerPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 21
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 13 3
1
<?php
2
3
namespace SfCod\QueueBundle\DependencyInjection\Compiler;
4
5
use SfCod\QueueBundle\Base\JobResolverInterface;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
/**
11
 * Class JobCompilerPass
12
 *
13
 * @author Virchenko Maksim <[email protected]>
14
 *
15
 * @package SfCod\QueueBundle\DependencyInjection\Compiler
16
 */
17
class JobCompilerPass implements CompilerPassInterface
18
{
19
    /**
20
     * Find all job handlers and mark them as public in case to work properly with job queue
21
     *
22
     * @param ContainerBuilder $container
23
     */
24
    public function process(ContainerBuilder $container)
25
    {
26
        if (!$container->hasDefinition(JobResolverInterface::class)) {
27
            return;
28
        }
29
30
        $jobResolver = $container->getDefinition(JobResolverInterface::class);
31
        $taggedServices = $container->findTaggedServiceIds('sfcod.jobqueue.job');
32
33
        foreach ($taggedServices as $id => $tags) {
34
            $jobResolver->addMethodCall('addJob', [$id, new Reference($id)]);
35
        }
36
    }
37
}
38