SenderServiceFactory::__invoke()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 10
cts 10
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 2
nop 1
crap 4
1
<?php
2
/**
3
 * MtMail - e-mail module for Zend Framework
4
 *
5
 * @link      http://github.com/mtymek/MtMail
6
 * @copyright Copyright (c) 2013-2017 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
use MtMail\Service\SenderPluginManager;
15
16
class SenderServiceFactory
17
{
18 2
    public function __invoke(ContainerInterface $serviceLocator)
19
    {
20 2
        $configuration = $serviceLocator->get('Configuration');
21 2
        $transportName = $configuration['mt_mail']['transport'];
22 2
        $service = new Sender($serviceLocator->get($transportName));
23
24 2
        if (isset($configuration['mt_mail']['sender_plugins'])
25 2
            && is_array($configuration['mt_mail']['sender_plugins'])
26
        ) {
27 1
            $pluginManager = $serviceLocator->get(SenderPluginManager::class);
28 1
            foreach (array_unique($configuration['mt_mail']['sender_plugins']) as $plugin) {
29 1
                $pluginManager->get($plugin)->attach($service->getEventManager());
30
            }
31
        }
32
33 2
        return $service;
34
    }
35
}
36