Failed Conditions
Push — master ( 4252f4...9d8e13 )
by Adrien
07:13
created

TransportFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 24
rs 10
c 0
b 0
f 0
ccs 8
cts 9
cp 0.8889
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 Application\Service;
6
7
use Interop\Container\ContainerInterface;
8
use Zend\Mail\Transport\InMemory;
9
use Zend\Mail\Transport\Smtp;
10
use Zend\Mail\Transport\SmtpOptions;
11
use Zend\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 1
    public function __invoke(ContainerInterface $container): TransportInterface
23
    {
24 1
        $config = $container->get('config');
25
26
        // Setup SMTP transport, or a mock one
27 1
        $configSmtp = $config['smtp'] ?? null;
28 1
        if ($configSmtp) {
29 1
            $transport = new Smtp();
30 1
            $options = new SmtpOptions($config['smtp']);
31 1
            $transport->setOptions($options);
32
        } else {
33
            $transport = new InMemory();
34
        }
35
36 1
        return $transport;
37
    }
38
}
39