Completed
Pull Request — master (#227)
by Carlos
05:59
created

MailerCompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
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 26
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

1 Method

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