Passed
Push — main ( 8365e4...b2f486 )
by Peter
03:33
created

TransportBootstrapper::createSmtpTransport()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 11
nc 4
nop 0
dl 0
loc 21
rs 9.9
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Bootstrappers\Email;
6
7
use AbterPhp\Framework\Constant\Env;
8
use AbterPhp\Framework\Environments\Environment;
9
use AbterPhp\Framework\Exception\Config;
10
use Opulence\Ioc\Bootstrappers\Bootstrapper;
11
use Opulence\Ioc\Bootstrappers\ILazyBootstrapper;
12
use Opulence\Ioc\IContainer;
13
use Symfony\Component\Mailer\Transport;
14
use Symfony\Component\Mailer\Transport\TransportInterface;
15
16
class TransportBootstrapper extends Bootstrapper implements ILazyBootstrapper
17
{
18
    /**
19
     * @inheritdoc
20
     */
21
    public function getBindings(): array
22
    {
23
        return [
24
            TransportInterface::class,
25
        ];
26
    }
27
28
    /**
29
     * @inheritdoc
30
     */
31
    public function registerBindings(IContainer $container): void
32
    {
33
        try {
34
            $transport = Transport::fromDsn(Environment::getVar(Env::EMAIL_DNS));
0 ignored issues
show
Bug introduced by
It seems like AbterPhp\Framework\Envir...onstant\Env::EMAIL_DNS) can also be of type null; however, parameter $dsn of Symfony\Component\Mailer\Transport::fromDsn() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
            $transport = Transport::fromDsn(/** @scrutinizer ignore-type */ Environment::getVar(Env::EMAIL_DNS));
Loading history...
35
            $container->bindInstance(TransportInterface::class, $transport);
36
        } catch (\Throwable $e) {
37
            throw new Config(TransportInterface::class, [Env::EMAIL_DNS], $e->getCode(), $e);
38
        }
39
    }
40
}
41