GatewayTagCompilerPass::process()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 17
cp 0
rs 9.2568
c 0
b 0
f 0
cc 5
nc 5
nop 1
crap 30
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