Passed
Push — 2.x ( a2237c...c5863b )
by Terry
02:56
created

ItemSmtp::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 1
dl 0
loc 18
rs 9.8666
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Shieldon package.
4
 *
5
 * (c) Terry L. <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace Shieldon\Firewall\Firewall\Messenger;
14
15
use Shieldon\Messenger\Messenger\MessengerInterface;
16
use Shieldon\Messenger\Smtp;
17
use function Shieldon\Firewall\__;
18
19
/**
20
 * The get for SMTP.
21
 */
22
class ItemSmtp
23
{
24
    /**
25
     * Initialize and get the instance.
26
     *
27
     * @param array $setting The configuration of that messanger.
28
     *
29
     * @return MessengerInterface
30
     */
31
    public static function get(array $setting): MessengerInterface
32
    {
33
        $sender     = $setting['config']['sender']     ?? '';
34
        $recipients = $setting['config']['recipients'] ?? [];
35
        $host       = $setting['config']['host']       ?? '';
36
        $user       = $setting['config']['user']       ?? '';
37
        $pass       = $setting['config']['pass']       ?? '';
38
        $port       = $setting['config']['port'] ?? '';
39
40
        $instance = new Smtp($user, $pass, $host, (int) $port);
41
        $instance->setSubject(__('core', 'messenger_text_mail_subject'));
42
        $instance->addSender($sender);
43
44
        foreach ($recipients as $recipient) {
45
            $instance->addRecipient($recipient);
46
        }
47
48
        return $instance;
49
    }
50
}