Completed
Pull Request — master (#311)
by Łukasz
03:20
created

ContextPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 20 4
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * (c) FSi sp. z o.o. <[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
12
namespace FSi\Bundle\AdminBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
17
class ContextPass implements CompilerPassInterface
18
{
19
    public function process(ContainerBuilder $container): void
20
    {
21
        if (!$container->hasDefinition('admin.context.manager')) {
22
            return;
23
        }
24
25
        $contexts = [];
26
        foreach ($container->findTaggedServiceIds('admin.context') as $id => $tags) {
27
            $priority = $tags[0]['priority'] ?? 0;
28
            $contexts[$priority][] = $container->findDefinition($id);
29
        }
30
31
        if (empty($contexts)) {
32
            return;
33
        }
34
        krsort($contexts);
35
        $contexts = array_merge(...$contexts);
36
37
        $container->findDefinition('admin.context.manager')->replaceArgument(0, $contexts);
38
    }
39
}
40