Passed
Push — pulls/4/swiftmailer-v6-support ( 5c5491...5a5bbc )
by Steve
13:37 queued 06:38
created

Swift_MailTransport::getDependencies()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 13
rs 9.9332
1
<?php
2
3
/**
4
 * This file was copied in from swiftmailer/swiftmailer v5.4.12 after it was removed from switftmailer v6
5
 * It has been slightly modified to meet phpcs standards and initialise Swift_DependencyContainer
6
 */
7
8
/*
9
 * This file is part of SwiftMailer.
10
 * (c) 2004-2009 Chris Corbyn
11
 *
12
 * For the full copyright and license information, please view the LICENSE file (MIT)
13
 * https://github.com/swiftmailer/swiftmailer/blob/181b89f18a90f8925ef805f950d47a7190e9b950/LICENSE
14
 */
15
16
/**
17
 * Sends Messages using the mail() function.
18
 *
19
 * @author Chris Corbyn
20
 *
21
 * at deprecated since 5.4.5 (to be removed in 6.0)
22
 *
23
 * @internal
24
 */
25
// @codingStandardsIgnoreStart
26
// ignore missing namespace
27
class Swift_MailTransport extends Swift_Transport_MailTransport
28
// @codingStandardsIgnoreEnd
29
{
30
    /**
31
     * Create a new MailTransport, optionally specifying $extraParams.
32
     *
33
     * @param string $extraParams
34
     */
35
    public function __construct($extraParams = '-f%s')
36
    {
37
        call_user_func_array(
38
            [$this, 'Swift_Transport_MailTransport::__construct'],
39
            $this->getDependencies()
40
        );
41
42
        $this->setExtraParams($extraParams);
43
    }
44
45
    /**
46
     * Create a new MailTransport instance.
47
     *
48
     * @param string $extraParams To be passed to mail()
49
     *
50
     * @return self
51
     */
52
    public static function newInstance($extraParams = '-f%s')
53
    {
54
        return new self($extraParams);
55
    }
56
57
    /**
58
     * Add in deps for MailTransport which was removed as part of SwiftMailer v6
59
     * @see transport_deps.php
60
     *
61
     * @return array
62
     */
63
    private function getDependencies(): array
64
    {
65
        $deps = Swift_DependencyContainer::getInstance()->createDependenciesFor('transport.mail');
66
        if (empty($deps)) {
67
            Swift_DependencyContainer::getInstance()
68
                ->register('transport.mail')
69
                ->asNewInstanceOf('Swift_Transport_MailTransport')
70
                ->withDependencies(['transport.mailinvoker', 'transport.eventdispatcher'])
71
                ->register('transport.mailinvoker')
72
                ->asSharedInstanceOf('Swift_Transport_SimpleMailInvoker');
73
            $deps = Swift_DependencyContainer::getInstance()->createDependenciesFor('transport.mail');
74
        }
75
        return $deps;
76
    }
77
}
78