IpCollector   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIdentifier() 0 3 1
A collect() 0 11 3
1
<?php
2
3
namespace Startwind\Inventorio\Collector\System\General;
4
5
use Startwind\Inventorio\Collector\Collector;
6
7
/**
8
 * This collector returns details about the operating system.
9
 *
10
 * - family: the OS family (MacOs, Linux, Windows). Please use the provided constants.
11
 * - version: the OS version
12
 *
13
 */
14
class IpCollector implements Collector
15
{
16
    protected const COLLECTION_IDENTIFIER = 'SystemIp';
17
18
    /**
19
     * @inheritDoc
20
     */
21
    public function getIdentifier(): string
22
    {
23
        return self::COLLECTION_IDENTIFIER;
24
    }
25
26
    /**
27
     * @inheritDoc
28
     */
29
    public function collect(): array
30
    {
31
        $ip = @file_get_contents('https://checkip.amazonaws.com');
32
33
        if (!$ip) {
34
            return [];
35
        }
36
37
        $ip = trim($ip);
38
39
        return ['ip' => filter_var($ip, FILTER_VALIDATE_IP) ? $ip : null];
40
    }
41
}
42