Completed
Push — 15.x ( b45baa...4ca9b4 )
by Tim
02:13
created

SendmailTransportMailerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 26
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A factory() 0 15 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Loggers\SwiftMailer\SendmailTransportMailerFactory
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Loggers\SwiftMailer;
22
23
use TechDivision\Import\Utils\SwiftMailerKeys;
24
use TechDivision\Import\Configuration\SwiftMailer\TransportConfigurationInterface;
25
26
/**
27
 * Factory implementation for a swift mailer with a simple sendmail transport.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import
33
 * @link      http://www.techdivision.com
34
 */
35
class SendmailTransportMailerFactory implements TransportMailerFactoryInterface
36
{
37
38
    /**
39
     * Creates a new swift mailer instance based on the passed transport configuration.
40
     *
41
     * @param \TechDivision\Import\Configuration\SwiftMailer\TransportConfigurationInterface $transportConfiguration The mailer configuration
42
     *
43
     * @return \Swift_Mailer The mailer instance
44
     */
45
    public function factory(TransportConfigurationInterface $transportConfiguration)
46
    {
47
48
        // initialize and load the sendmail command parameter
49
        $command = '/usr/sbin/sendmail -bs';
50
        if ($transportConfiguration->hasParam(SwiftMailerKeys::COMMAND)) {
51
            $command = $transportConfiguration->getParam(SwiftMailerKeys::COMMAND);
52
        }
53
54
        // initialize and create the mailer transport instance
55
        $transport = \Swift_SendmailTransport::newInstance($command);
56
57
        // initialize, create and return the swift mailer instance
58
        return \Swift_Mailer::newInstance($transport);
59
    }
60
}
61