Completed
Push — master ( f5aed6...aebd89 )
by Nikola
05:02
created

NotificationsCompilerPass   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 31
ccs 0
cts 20
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 25 6
1
<?php
2
/*
3
 * This file is part of the Exchange Rate Bundle, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass;
11
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
15
16
/**
17
 * Class NotificationsCompilerPass
18
 *
19
 * Compiler pass for notifications
20
 *
21
 * @package RunOpenCode\Bundle\ExchangeRate\DependencyInjection\CompilerPass
22
 */
23
class NotificationsCompilerPass implements CompilerPassInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function process(ContainerBuilder $container)
29
    {
30
        if (!$container->hasDefinition('runopencode.exchange_rate.notifications.email')) {
31
            return;
32
        }
33
34
        if (!$container->hasParameter('runopencode.exchange_rate.notifications.e_mail')) {
35
            $container->removeDefinition('runopencode.exchange_rate.notifications.email');
36
            return;
37
        }
38
39
        if (!$container->hasDefinition('mailer') || !class_exists('\\Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle')) {
40
            throw new RuntimeException('Bundle "symfony/swiftmailer-bundle" is required for email notifications.');
41
        }
42
43
        $recipients = $container->getParameter('runopencode.exchange_rate.notifications.e_mail');
44
45
        if (0 === count($recipients)) {
46
            throw new RuntimeException('At least one recipient for e-mail notifications must be provided.');
47
        }
48
49
        $container
50
            ->getDefinition('runopencode.exchange_rate.notifications.e_mail')
51
            ->addArgument($recipients);
52
    }
53
}
54