GatewayTagCompilerPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 28
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 22 5
1
<?php
2
3
/*
4
 * This file is part of the colinodell\omnipay-bundle package.
5
 *
6
 * (c) 2018 Colin O'Dell <[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 ColinODell\OmnipayBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
class GatewayTagCompilerPass implements CompilerPassInterface
19
{
20
    /**
21
     * @param ContainerBuilder $container
22
     */
23
    public function process(ContainerBuilder $container)
24
    {
25
        if (!$container->hasDefinition('omnipay')) {
26
            return;
27
        }
28
29
        $definition = $container->findDefinition('omnipay');
30
31
        $taggedGateways = $container->findTaggedServiceIds('omnipay.gateway');
32
        foreach ($taggedGateways as $id => $tags) {
33
            foreach ($tags as $tag) {
34
                $args = [new Reference($id)];
35
36
                // Reference the gateway by the alias if provided
37
                if (isset($tag['alias'])) {
38
                    $args[] = $tag['alias'];
39
                }
40
41
                $definition->addMethodCall('registerGateway', $args);
42
            }
43
        }
44
    }
45
}
46