MailPackage   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A addToContainer() 0 22 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Bone\Mail;
6
7
use Barnacle\Container;
8
use Barnacle\RegistrationInterface;
9
use Bone\View\ViewEngine;
10
use Bone\Server\Environment;
11
use Bone\Server\SiteConfig;
12
use Bone\Mail\Service\MailService;
13
use Laminas\Mail\Transport\Sendmail;
14
use Laminas\Mail\Transport\Smtp;
15
use Laminas\Mail\Transport\SmtpOptions;
16
17
class MailPackage implements RegistrationInterface
18
{
19
    /**
20
     * @param Container $c
21
     */
22 1
    public function addToContainer(Container $c)
23
    {
24 1
        $c[MailService::class] = $c->factory(function (Container $c) {
25 1
            $view = $c->get(ViewEngine::class);
26 1
            $siteConfig = $c->get(SiteConfig::class);
27 1
            $mailService = new MailService();
28 1
            $transport = new Sendmail();
29
30 1
            if ($c->has('mail')) {
31 1
                $settings = $c->get('mail');
32
33 1
                if (isset($settings['name'], $settings['host'], $settings['port'])) {
34 1
                    $options = new SmtpOptions($settings);
35 1
                    $transport = new Smtp($options);
36
                }
37
            }
38
39 1
            $mailService->setView($view);
40 1
            $mailService->setSiteConfig($siteConfig);
41 1
            $mailService->setTransport($transport);
42
43 1
            return $mailService;
44 1
        });
45
    }
46
}
47