TransportFactory::create()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 11
ccs 9
cts 9
cp 1
crap 4
rs 9.9666
1
<?php
2
3
namespace Da\Mailer\Transport;
4
5
use Da\Mailer\Enum\TransportType;
6
use Da\Mailer\Exception\InvalidTransportTypeArgumentException;
7
8
class TransportFactory
9
{
10
    /**
11
     * Creates one of the transport supported according to the type passed.
12
     *
13
     * @param array $options the options to configure the transport
14
     * @param string $type the type of transport
15
     *
16 2
     * @return MailTransportFactory|SendMailTransportFactory|SmtpTransportFactory
17
     */
18
    public static function create(array $options, $type)
19 2
    {
20 1
        switch ($type) {
21 2
            case TransportType::SEND_MAIL:
22 1
                return new SendMailTransportFactory($options);
23 2
            case TransportType::MAIL:
24 1
                return new MailTransportFactory($options);
25 1
            case TransportType::SMTP:
26 1
                return new SmtpTransportFactory($options);
27 1
            default:
28
                throw new InvalidTransportTypeArgumentException("Unknown TransportType: '{$type}'");
29
        }
30
    }
31
}
32