WebProsMonitoringCollector   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A collect() 0 19 4
A getIdentifier() 0 3 1
1
<?php
2
3
namespace Startwind\Inventorio\Collector\Application\Monitoring;
4
5
use Startwind\Inventorio\Collector\Collector;
6
use Startwind\Inventorio\Exec\Runner;
7
8
class WebProsMonitoringCollector implements Collector
9
{
10
    protected const INI_FILE = '/etc/agent360-token.ini';
11
12
    protected const COLLECTION_IDENTIFIER = 'WebProsMonitoring';
13
14
    /**
15
     * @inheritDoc
16
     */
17
    public function getIdentifier(): string
18
    {
19
        return self::COLLECTION_IDENTIFIER;
20
    }
21
22
    /**
23
     * @inheritDoc
24
     */
25
    public function collect(): array
26
    {
27
        $runner = Runner::getInstance();
28
29
        if (!$runner->fileExists(self::INI_FILE)) return [];
30
31
        $config = $runner->getFileContents(self::INI_FILE, true);
32
33
        $configArray = [];
34
35
        foreach ($config as $line) {
36
            if (str_starts_with($line, '[')) continue;
37
            $element = explode('=', $line);
38
            $configArray[$element[0]] = trim($element[1]);
39
        }
40
41
        return [
42
            'server' => $configArray['server'],
43
            'user' => $configArray['user']
44
        ];
45
    }
46
}
47