Failed Conditions
Push — master ( 398dce...01f535 )
by Adrien
02:21
created

TransportFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 24
ccs 0
cts 12
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Service;
6
7
use Interop\Container\ContainerInterface;
8
use Laminas\Mail\Transport\InMemory;
9
use Laminas\Mail\Transport\Smtp;
10
use Laminas\Mail\Transport\SmtpOptions;
11
use Laminas\Mail\Transport\TransportInterface;
12
13
class TransportFactory
14
{
15
    /**
16
     * Return a configured mail transport
17
     *
18
     * @param ContainerInterface $container
19
     *
20
     * @return TransportInterface
21
     */
22
    public function __invoke(ContainerInterface $container): TransportInterface
23
    {
24
        $config = $container->get('config');
25
26
        // Setup SMTP transport, or a mock one
27
        $configSmtp = $config['smtp'] ?? null;
28
        if ($configSmtp) {
29
            $transport = new Smtp();
30
            $options = new SmtpOptions($config['smtp']);
31
            $transport->setOptions($options);
32
        } else {
33
            $transport = new InMemory();
34
        }
35
36
        return $transport;
37
    }
38
}
39