Passed
Push — 2.x ( 75d9da...077994 )
by Terry
01:57
created

ItemSendgrid::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 15
rs 9.9666
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\Panel\get;
14
15
use Shieldon\Messenger\Messenger\MessengerInterface;
16
use Shieldon\Messenger\Sendgrid;
17
18
/**
19
 * The get for Sendgrid.
20
 */
21
class ItemSendgrid
22
{
23
    /**
24
     * Initialize and get the instance.
25
     *
26
     * @param array $setting The configuration of that messanger.
27
     *
28
     * @return MessengerInterface
29
     */
30
    public static function get(array $setting): MessengerInterface
31
    {
32
        $apiKey = $setting['config']['api_key'] ?? '';
33
        $sender = $setting['config']['sender'] ?? '';
34
        $recipients = $setting['config']['recipients'] ?? [];
35
36
        $instance = new Sendgrid($apiKey);
37
        $instance->setSubject(__('core', 'messenger_text_mail_subject'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        $instance->setSubject(/** @scrutinizer ignore-call */ __('core', 'messenger_text_mail_subject'));
Loading history...
38
        $instance->addSender($sender);
39
40
        foreach ($recipients as $recipient) {
41
            $instance->addRecipient($recipient);
42
        }
43
44
        return $instance;
45
    }
46
}