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

ItemMailgun::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 0
loc 16
rs 9.9332
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\Mailgun;
17
use function Shieldon\Firewall\__;
18
19
/**
20
 * Get an item of messenger. It is Mailgun.
21
 */
22
class ItemMailgun
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
        $apiKey     = $setting['config']['api_key']     ?? '';
34
        $domain     = $setting['config']['domain_name'] ?? '';
35
        $sender     = $setting['config']['sender']      ?? '';
36
        $recipients = $setting['config']['recipients']  ?? [];
37
38
        $instance = new Mailgun($apiKey, $domain);
39
        $instance->setSubject(__('core', 'messenger_text_mail_subject'));
40
        $instance->addSender($sender);
41
42
        foreach ($recipients as $recipient) {
43
            $instance->addRecipient($recipient);
44
        }
45
46
        return $instance;
47
    }
48
}