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

TransportFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2.0054

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 15
rs 9.9666
c 0
b 0
f 0
ccs 8
cts 9
cp 0.8889
crap 2.0054
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