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

ItemSendgrid::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 15
rs 9.9666
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\Sendgrid;
17
use function Shieldon\Firewall\__;
18
19
/**
20
 * The get for Sendgrid.
21
 */
22
class ItemSendgrid
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
        $sender = $setting['config']['sender'] ?? '';
35
        $recipients = $setting['config']['recipients'] ?? [];
36
37
        $instance = new Sendgrid($apiKey);
38
        $instance->setSubject(__('core', 'messenger_text_mail_subject'));
39
        $instance->addSender($sender);
40
41
        foreach ($recipients as $recipient) {
42
            $instance->addRecipient($recipient);
43
        }
44
45
        return $instance;
46
    }
47
}