Completed
Pull Request — master (#29)
by Mateusz
37:30 queued 34:33
created

SenderServiceFactory::__invoke()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 9.2
cc 4
eloc 10
nc 2
nop 1
crap 4
1
<?php
2
/**
3
 * MtMail - e-mail module for Zend Framework 2
4
 *
5
 * @link      http://github.com/mtymek/MtMail
6
 * @copyright Copyright (c) 2013-2014 Mateusz Tymek
7
 * @license   BSD 2-Clause
8
 */
9
10
namespace MtMail\Factory;
11
12
use Interop\Container\ContainerInterface;
13
use MtMail\Service\Sender;
14
15
class SenderServiceFactory
16
{
17
    public function __invoke(ContainerInterface $serviceLocator)
18
    {
19
        $configuration = $serviceLocator->get('Configuration');
20
        $transportName = $configuration['mt_mail']['transport'];
21
        $service = new Sender($serviceLocator->get($transportName));
22
23
        if (isset($configuration['mt_mail']['sender_plugins'])
24
            && is_array($configuration['mt_mail']['sender_plugins'])
25 2
        ) {
26
            $pluginManager = $serviceLocator->get('MtMail\Service\SenderPluginManager');
27 2
            foreach (array_unique($configuration['mt_mail']['sender_plugins']) as $plugin) {
28 2
                $service->getEventManager()->attachAggregate($pluginManager->get($plugin));
0 ignored issues
show
Bug introduced by
The method attachAggregate() does not exist on Zend\EventManager\EventManagerInterface. Did you maybe mean attach()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
29 2
            }
30
        }
31 2
32 2
        return $service;
33 2
    }
34
}
35