Completed
Push — master ( ac7204...285e3a )
by Emily
03:59
created

configureMailer()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 22
cts 22
cp 1
rs 8.439
c 0
b 0
f 0
cc 5
eloc 20
nc 2
nop 3
crap 5
1
<?php
2
3
/*
4
 * This file is part of the pixelart Swiftmailer manipulator bundle.
5
 *
6
 * (c) pixelart GmbH
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Pixelart\Bundle\SwiftmailerManipulatorBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\DefinitionDecorator;
17
use Symfony\Component\DependencyInjection\Extension\Extension;
18
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
19
20
class PixelartSwiftmailerManipulatorExtension extends Extension
21
{
22 40
    public function load(array $configs, ContainerBuilder $container)
23
    {
24 40
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
25 40
        $loader->load('services.xml');
26
27 40
        $configuration = $this->getConfiguration($configs, $container);
28 40
        $config = $this->processConfiguration($configuration, $configs);
1 ignored issue
show
Documentation introduced by
$configuration is of type object|null, but the function expects a object<Symfony\Component...ConfigurationInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
29
30 40
        foreach ($config['mailers'] as $name => $mailer) {
31 30
            $this->configureMailer($name, $mailer, $container);
32 24
        }
33 40
    }
34
35 30
    private function configureMailer($name, array $mailer, ContainerBuilder $container)
36
    {
37
        if (
38 30
            (isset($mailer['prepend_subject']) && $mailer['prepend_subject'])
39 12
            || (isset($mailer['prepend_body']) && $mailer['prepend_body'])
40 18
        ) {
41 30
            $container->setParameter(
42 30
                sprintf('pixelart_swiftmailer_manipulator.mailer.%s.prepend_subject', $name),
43 30
                $mailer['prepend_subject']
44 18
            );
45 30
            $container->setParameter(
46 30
                sprintf('pixelart_swiftmailer_manipulator.mailer.%s.prepend_body', $name),
47 30
                $mailer['prepend_body']
48 18
            );
49
50 30
            $definitionDecorator = new DefinitionDecorator('pixelart_swiftmailer_manipulator.plugin.abstract');
51
            $container
52 30
                ->setDefinition(
53 30
                    sprintf('pixelart_swiftmailer_manipulator.mailer.%s.plugin', $name),
54
                    $definitionDecorator
55 18
                )
56 30
                ->addArgument(sprintf('%%pixelart_swiftmailer_manipulator.mailer.%s.prepend_subject%%', $name))
57 30
                ->addArgument(sprintf('%%pixelart_swiftmailer_manipulator.mailer.%s.prepend_body%%', $name))
58
            ;
59
60
            $container
61 30
                ->getDefinition(sprintf('pixelart_swiftmailer_manipulator.mailer.%s.plugin', $name))
62 30
                ->addTag(sprintf('swiftmailer.%s.plugin', $name))
63
            ;
64 18
        }
65 30
    }
66
}
67