Completed
Pull Request — master (#1)
by Yanick
02:41
created

AddTaskFactoryPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 27 6
1
<?php
2
3
/**
4
 * This file is part of tenside/core-bundle.
5
 *
6
 * (c) Christian Schiffler <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * This project is provided in good faith and hope to be usable by anyone.
12
 *
13
 * @package    tenside/core-bundle
14
 * @author     Yanick Witschi <[email protected]>
15
 * @copyright  2015 Christian Schiffler <[email protected]>
16
 * @license    https://github.com/tenside/core-bundle/blob/master/LICENSE MIT
17
 * @link       https://github.com/tenside/core-bundle
18
 * @filesource
19
 */
20
21
namespace Tenside\CoreBundle\DependencyInjection\Compiler;
22
23
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
24
use Symfony\Component\DependencyInjection\ContainerBuilder;
25
use Symfony\Component\DependencyInjection\Reference;
26
27
/**
28
 * Registers the task factories
29
 */
30
class AddTaskFactoryPass implements CompilerPassInterface
31
{
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function process(ContainerBuilder $container)
36
    {
37
        if (!$container->hasDefinition('tenside.taskfactory')) {
38
            return;
39
        }
40
41
        $factories = [];
42
        foreach ($container->findTaggedServiceIds('tenside.taskfactory') as $id => $attributes) {
43
            $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
44
            $factories[$priority][] = new Reference($id);
45
        }
46
47
        if (0 === count($factories)) {
48
            return;
49
        }
50
51
        // sort by priority and flatten
52
        krsort($factories);
53
        $factories = call_user_func_array('array_merge', $factories);
54
55
        foreach ($factories as $factory) {
56
            $container->getDefinition('tenside.taskfactory')->addMethodCall(
57
                'add',
58
                [$factory]
59
            );
60
        }
61
    }
62
}
63