Completed
Push — master ( 42b6f8...140d5a )
by Antonio Carlos
06:38
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 4
    private function getActionMessage()
10
    {
11 4
        return config('firewall.notifications.message.message');
12
    }
13
14
    /**
15
     * @param $item
16
     *
17
     * @return string
18
     */
19 4
    protected function getMessage($item)
20
    {
21 4
        $domain = Request::server('SERVER_NAME');
22
23 4
        return sprintf($this->getActionMessage(), $domain, $this->makeMessage($item));
24
    }
25
26
    /**
27
     * @param $item
28
     *
29
     * @return mixed
30
     */
31 4
    protected function makeMessage($item)
32
    {
33 4
        $ip = "{$item['ipAddress']} - {$item['host']}";
34
35 4
        if ($item['type'] == 'ip') {
36 2
            return "$ip";
37
        }
38
39 3
        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 5
    public function makeGeolocation($item)
50
    {
51 5
        return collect([
52 5
            config('firewall.notifications.message.geolocation.field_latitude')     => $item['geoIp']['latitude'],
53 5
            config('firewall.notifications.message.geolocation.field_longitude')    => $item['geoIp']['longitude'],
54 5
            config('firewall.notifications.message.geolocation.field_country_code') => $item['geoIp']['country_code'],
55 5
            config('firewall.notifications.message.geolocation.field_country_name') => $item['geoIp']['country_name'],
56 5
            config('firewall.notifications.message.geolocation.field_city')         => $item['geoIp']['city'],
57 5
        ])->filter()->toArray();
58
    }
59
}
60