Passed
Push — 2.x ( 92ec38...c080f0 )
by Terry
02:07
created

SlackWebhook::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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\Sandbox;
14
15
use Shieldon\Messenger as Messenger;
16
17
/**
18
 * The sandbox for Slack Webhook.
19
 */
20
class SlackWebhook
21
{
22
    /**
23
     * Invoker.
24
     *
25
     * @param array $args
26
     *
27
     * @return bool
28
     */
29
    public function __invoke(array $args): bool
30
    {
31
        return $this->sandbox($args[0], $args[1]);
32
    }
33
34
    /**
35
     * Test Slack Webhook.
36
     *
37
     * @param array $getParams The GET params passed from tryMessenger method.
38
     * @param array $message   The message title and body.
39
     *
40
     * @return bool
41
     */
42
    private function sandbox($getParams, $message)
43
    {
44
        $webhookUrl = $getParams['webhookUrl'] ?? '';
45
        if (!empty($webhookUrl)) {
46
            $messenger = new Messenger\SlackWebhook($webhookUrl);
47
            if ($messenger->send($message['body'])) {
48
                return true;
49
            }
50
        }
51
        return false;
52
    }
53
}