Completed
Push — master ( aebd89...bf7cab )
by Nikola
05:35
created

NotificationsCompilerPass::process()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
ccs 14
cts 14
cp 1
rs 8.439
cc 6
eloc 14
nc 5
nop 1
crap 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 5
    public function process(ContainerBuilder $container)
29
    {
30 5
        if (!$container->hasDefinition('runopencode.exchange_rate.notifications.email')) {
31 1
            return;
32
        }
33
34 4
        if (!$container->hasParameter('runopencode.exchange_rate.notifications.email.recipients')) {
35 1
            $container->removeDefinition('runopencode.exchange_rate.notifications.email');
36 1
            return;
37
        }
38
39 3
        if (!$container->hasDefinition('mailer') || !class_exists('\\Symfony\\Bundle\\SwiftmailerBundle\\SwiftmailerBundle')) {
40 1
            throw new RuntimeException('Bundle "symfony/swiftmailer-bundle" is required for email notifications.');
41
        }
42
43 2
        $recipients = $container->getParameter('runopencode.exchange_rate.notifications.email.recipients');
44
45 2
        if (0 === count($recipients)) {
46 1
            throw new RuntimeException('At least one recipient for e-mail notifications must be provided.');
47
        }
48
49
        $container
50 1
            ->getDefinition('runopencode.exchange_rate.notifications.email')
51 1
            ->setArgument(2, $recipients);
52 1
    }
53
}
54