MailerCompilerPass   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 21 5
1
<?php
2
3
namespace Liip\MonitorBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
9
use Symfony\Component\DependencyInjection\Loader;
10
11
/**
12
 * @author Carlos Dominguez <[email protected]>
13
 */
14
class MailerCompilerPass implements CompilerPassInterface
15
{
16 8
    public function process(ContainerBuilder $container)
17
    {
18 8
        if (false === $container->hasParameter('liip_monitor.mailer.enabled')) {
19 1
            return;
20
        }
21
22 7
        if (false === $container->getParameter('liip_monitor.mailer.enabled')) {
23 1
            return;
24
        }
25
26
        try {
27 6
            $definition = $container->findDefinition('mailer');
28 2
        } catch (ServiceNotFoundException $e) {
29 2
            throw new \InvalidArgumentException('To enable mail reporting you have to install the "swiftmailer/swiftmailer" or "symfony/mailer".');
30
        }
31
32 4
        $filename = \Swift_Mailer::class !== $definition->getClass() ? 'symfony_mailer.xml' : 'swift_mailer.xml';
33
34 4
        $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
35 4
        $loader->load($filename);
36 4
    }
37
}
38