Test Failed
Push — master ( d3d0f9...cca6f2 )
by Julien
04:54
created

ServiceProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 13.33%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 16
c 3
b 1
f 0
dl 0
loc 27
ccs 2
cts 15
cp 0.1333
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 23 2
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Provider\Mailer;
13
14
use Phalcon\Di\DiInterface;
15
use Phalcon\Events\ManagerInterface;
16
use Phalcon\Mailer\Manager;
17
use Zemit\Config\ConfigInterface;
18
use Zemit\Provider\AbstractServiceProvider;
19
20
class ServiceProvider extends AbstractServiceProvider
21
{
22
    protected string $serviceName = 'mailer';
23
    
24 17
    public function register(DiInterface $di): void
25
    {
26 17
        $di->setShared($this->getName(), function () use ($di) {
27
    
28
            $config = $di->get('config');
29
            assert($config instanceof ConfigInterface);
30
    
31
            $mailerConfig = $config->pathToArray('mailer', []);
32
            
33
            $driver = $mailerConfig['driver'] ?? '';
34
            $defaultOptions = $mailerConfig['defaults'] ?? [];
35
            $driverOptions = $mailerConfig['drivers'][$driver] ?? [];
36
            $options = array_merge($defaultOptions, $driverOptions);
37
    
38
            $manager = new Manager($options);
39
            $manager->setDI($di);
40
            
41
            $eventsManager = $di->get('eventsManager');
42
            if ($eventsManager instanceof ManagerInterface) {
43
                $manager->setEventsManager($eventsManager);
44
            }
45
            
46
            return $manager;
47 17
        });
48
    }
49
}
50