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

BaseChannel   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 53
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getActionMessage() 0 4 1
A getMessage() 0 6 1
A makeMessage() 0 10 2
A makeGeolocation() 0 10 1
1
<?php
2
3
namespace PragmaRX\Firewall\Notifications\Channels;
4
5
use Request;
6
7
abstract class BaseChannel implements Contract
8
{
9 2
    private function getActionMessage()
10
    {
11 2
        return config('firewall.notifications.message.message');
12
    }
13
14
    /**
15
     * @param $item
16
     *
17
     * @return string
18
     */
19 2
    protected function getMessage($item)
20
    {
21 2
        $domain = Request::server('SERVER_NAME');
22
23 2
        return sprintf($this->getActionMessage(), $domain, $this->makeMessage($item));
24
    }
25
26
    /**
27
     * @param $item
28
     *
29
     * @return mixed
30
     */
31 2
    protected function makeMessage($item)
32
    {
33 2
        $ip = "{$item['ipAddress']} - {$item['host']}";
34
35 2
        if ($item['type'] == 'ip') {
36 1
            return "$ip";
37
        }
38
39 2
        return "{$item['country_code']}-{$item['country_name']} ({$ip})";
40
    }
41
42
    /**
43
     * Make a geolocation model for the item.
44
     *
45
     * @param $item
46
     *
47
     * @return array
48
     */
49 2
    public function makeGeolocation($item)
50
    {
51 2
        return collect([
52 2
            config('firewall.notifications.message.geolocation.field_latitude')     => $item['geoIp']['latitude'],
53 2
            config('firewall.notifications.message.geolocation.field_longitude')    => $item['geoIp']['longitude'],
54 2
            config('firewall.notifications.message.geolocation.field_country_code') => $item['geoIp']['country_code'],
55 2
            config('firewall.notifications.message.geolocation.field_country_name') => $item['geoIp']['country_name'],
56 2
            config('firewall.notifications.message.geolocation.field_city')         => $item['geoIp']['city'],
57 2
        ])->filter()->toArray();
58
    }
59
}
60