Completed
Push — master ( 85b241...3d718b )
by Antonio Carlos
05:58 queued 02:30
created

Slack   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 87.88%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 53
ccs 29
cts 33
cp 0.8788
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B send() 0 42 3
1
<?php
2
3
namespace PragmaRX\Firewall\Notifications\Channels;
4
5
use Carbon\Carbon;
6
use Illuminate\Notifications\Messages\SlackMessage;
7
8
class Slack extends BaseChannel implements Contract
9
{
10
    /**
11
     * Send a message.
12
     *
13
     * @param $notifiable
14
     * @param $item
15
     *
16
     * @return \Illuminate\Notifications\Messages\SlackMessage
17
     */
18 1
    public function send($notifiable, $item)
19
    {
20 1
        $message = (new SlackMessage())
21 1
            ->error()
22 1
            ->from(
23 1
                config('firewall.notifications.from.name'),
24 1
                config('firewall.notifications.from.icon_emoji')
25
            )
26 1
            ->content($this->getMessage($item))
27 1
            ->attachment(function ($attachment) use ($item) {
28 1
                $attachment->title(config('firewall.notifications.message.request_count.title'))
29 1
                            ->content(
30 1
                                sprintf(
31 1
                                    config('firewall.notifications.message.request_count.message'),
32 1
                                    $item['requestCount'],
33 1
                                    $item['firstRequestAt']->diffInSeconds(Carbon::now()),
34 1
                                    (string) $item['firstRequestAt']
35
                                )
36
                            );
37 1
            })
38 1
            ->attachment(function ($attachment) use ($item) {
39 1
                $attachment->title($title = config('firewall.notifications.message.uri.title'))
40 1
                           ->content($item['server']['REQUEST_URI']);
41 1
            })
42 1
            ->attachment(function ($attachment) use ($item) {
43 1
                $attachment->title(config('firewall.notifications.message.user_agent.title'))
44 1
                           ->content($item['userAgent']);
45 1
            })
46 1
            ->attachment(function ($attachment) use ($item) {
47 1
                $attachment->title(config('firewall.notifications.message.blacklisted.title'))
48 1
                           ->content($item['isBlacklisted'] ? 'YES' : 'NO');
49 1
            });
50
51 1
        if ($item['geoIp']) {
52
            $message->attachment(function ($attachment) use ($item) {
53
                $attachment->title(config('firewall.notifications.message.geolocation.title'))
54
                           ->fields($this->makeGeolocation($item));
55
            });
56
        }
57
58
        return $message;
59
    }
60
}
61