Passed
Push — master ( 42f56d...5820e4 )
by Nils
03:51 queued 17s
created

getActiveApacheModules()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 20
rs 9.9332
1
<?php
2
3
namespace Startwind\Inventorio\Collector\Application\WebServer\Apache;
4
5
use Startwind\Inventorio\Collector\BasicCollector;
6
7
class ApacheConfigurationCollector extends BasicCollector
8
{
9
    public const COLLECTION_IDENTIFIER = 'ApacheModules';
10
11
    public function collect(): array
12
    {
13
        return [
14
            'modules' => $this->getActiveApacheModules()
15
        ];
16
    }
17
18
    private function getActiveApacheModules(): array
19
    {
20
        $output = [];
21
        $returnVar = 0;
22
23
        exec('apache2ctl -M 2>&1', $output, $returnVar);
24
25
        if ($returnVar !== 0) {
26
            return [];
27
        }
28
29
        $modules = [];
30
31
        foreach ($output as $line) {
32
            if (preg_match('/^\s*([a-z_]+)_module/', $line, $matches)) {
33
                $modules[] = $matches[1];
34
            }
35
        }
36
37
        return $modules;
38
    }
39
40
}
41