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

ASNCollector::collect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 10
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