SwiftMailerFactory::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Acelaya\Website\Factory;
5
6
use Interop\Container\ContainerInterface;
7
use Interop\Container\Exception\ContainerException;
8
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
9
use Zend\ServiceManager\Exception\ServiceNotFoundException;
10
use Zend\ServiceManager\Factory\FactoryInterface;
11
12
class SwiftMailerFactory implements FactoryInterface
13
{
14
    /**
15
     * Create an object
16
     *
17
     * @param  ContainerInterface $container
18
     * @param  string $requestedName
19
     * @param  null|array $options
20
     * @return object|\Swift_Mailer
21
     * @throws ServiceNotFoundException if unable to resolve the service.
22
     * @throws ServiceNotCreatedException if an exception is raised when
23
     *     creating a service.
24 1
     * @throws ContainerException if any other error occurs
25
     */
26 1
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null): \Swift_Mailer
27 1
    {
28 1
        $mailConfig = $container->get('config')['mail'];
29 1
        $smtp = $mailConfig['smtp'];
30 1
        $transport = \Swift_SmtpTransport::newInstance($smtp['server'], $smtp['port'], $smtp['ssl'])
31 1
                                         ->setUsername($smtp['username'])
32
                                         ->setPassword($smtp['password']);
33
        return new \Swift_Mailer($transport);
34
    }
35
}
36