Passed
Push — master ( 09abe6...8522f2 )
by Nils
02:23
created

ASNCollector   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdentifier() 0 3 1
A collect() 0 14 1
1
<?php
2
3
namespace Startwind\Inventorio\Collector\Hosting\HostingCompany;
4
5
use Startwind\Inventorio\Collector\Collector;
6
7
class ASNCollector implements Collector
8
{
9
    public function getIdentifier(): string
10
    {
11
        return 'AutonomousSystem';
12
    }
13
14
    public function collect(): array
15
    {
16
        // @todo use already collected ip address
17
        $ip = file_get_contents('https://api.ipify.org');
18
        $data = json_decode(file_get_contents("http://ip-api.com/json/" . $ip), true);
19
20
        $asnArray = explode(' ' , $data['as']);
21
22
        $asn = substr($asnArray[0], 2);
23
        $isp = $data['isp'];
24
25
        return [
26
            'asn' => $asn,
27
            'isp' => $isp
28
        ];
29
    }
30
}
31