SubscriberGatewayPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
dl 0
loc 23
rs 10
c 1
b 0
f 1
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 21 4
1
<?php
2
3
namespace MailMotor\Bundle\MailMotorBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
class SubscriberGatewayPass implements CompilerPassInterface
9
{
10
    public function process(ContainerBuilder $container): void
11
    {
12
        // always first check if the primary service is defined
13
        if (!$container->has('mailmotor.manager.subscriber_gateway')) {
14
            return;
15
        }
16
17
        $definition = $container->findDefinition('mailmotor.manager.subscriber_gateway');
18
19
        // find all service IDs with the app.mail_transport tag
20
        $taggedServices = $container->findTaggedServiceIds('mailmotor.subscriber_gateway');
21
22
        foreach ($taggedServices as $id => $tags) {
23
            // a service could have the same tag twice
24
            foreach ($tags as $attributes) {
25
                // add the subscriber gateway service to the SubscriberGatewayManager service
26
                $definition->addMethodCall(
27
                    'addSubscriberGateway',
28
                    [
29
                        $id,
30
                        $attributes['alias']
31
                    ]
32
                );
33
            }
34
        }
35
    }
36
}
37