Passed
Push — master ( 3d0d87...075b69 )
by Antonio Carlos
09:13
created

Mail::send()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 3.0017

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 16
cts 17
cp 0.9412
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 17
nc 2
nop 2
crap 3.0017
1
<?php
2
3
namespace PragmaRX\Firewall\Notifications\Channels;
4
5
use Carbon\Carbon;
6
use Illuminate\Notifications\Messages\MailMessage;
7
8
class Mail 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 2
    public function send($notifiable, $item)
19
    {
20 2
        $message = (new MailMessage())
21 2
            ->from(
22 2
                config('firewall.notifications.from.name'),
23 2
                config('firewall.notifications.from.icon_emoji')
24
            )
25 2
            ->subject(config('firewall.notifications.message.request_count.title'))
26 2
            ->line(sprintf(
27 2
                config('firewall.notifications.message.request_count.message'),
28 2
                $item['requestCount'],
29 2
                $item['firstRequestAt']->diffInSeconds(Carbon::now()),
30 2
                (string) $item['firstRequestAt']
31
            ))
32 2
            ->line(config('firewall.notifications.message.uri.title').': '.$item['server']['REQUEST_URI'])
33 2
            ->line(config('firewall.notifications.message.user_agent.title').': '.$item['userAgent'])
34 2
            ->line(config('firewall.notifications.message.blacklisted.title').': '.$item['isBlacklisted'] ? 'YES' : 'NO')
35
        ;
36
37 2
        if ($item['geoIp']) {
38 2
            $message->line(config('firewall.notifications.message.geolocation.title').': '.$this->makeGeolocation($item));
39
        }
40
41
        return $message;
42
    }
43
}
44