Passed
Pull Request — master (#873)
by butschster
07:05
created

TransportResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\SendIt;
6
7
use Symfony\Component\Mailer\Transport;
8
use Symfony\Component\Mailer\Transport\Dsn;
9
use Symfony\Component\Mailer\Transport\TransportFactoryInterface;
10
use Symfony\Component\Mailer\Transport\TransportInterface;
11
12
final class TransportResolver implements TransportResolverInterface, TransportRegistryInterface
13
{
14
    /** @var TransportFactoryInterface[] */
15
    private array $transports = [];
16
17 8
    public function __construct(
18
        private readonly Transport $transport,
19
    ) {
20 8
    }
21
22 3
    public function registerTransport(TransportFactoryInterface $factory): void
23
    {
24 3
        $this->transports[] = $factory;
25
    }
26
27 6
    public function resolve(string $dsn): TransportInterface
28
    {
29 6
        $dsnDto = Dsn::fromString($dsn);
30 6
        foreach ($this->transports as $transport) {
31 2
            if ($transport->supports($dsnDto)) {
32 1
                return $transport->create($dsnDto);
33
            }
34
        }
35
36 5
        return $this->transport->fromString($dsn);
37
    }
38
39 1
    public function getTransports(): array
40
    {
41 1
        return $this->transports;
42
    }
43
}
44