Passed
Push — master ( c9bbee...06663f )
by Nils
02:53
created

WebserverUtil   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractDocumentRootByKey() 0 15 4
A extractDocumentRoots() 0 6 1
1
<?php
2
3
namespace Startwind\Inventorio\Util;
4
5
use Startwind\Inventorio\Collector\Application\WebServer\Apache\ApacheServerNameCollector;
6
use Startwind\Inventorio\Collector\Application\WebServer\Nginx\NginxServerNameCollector;
7
8
abstract class WebserverUtil
9
{
10
    public static function extractDocumentRoots(array $inventory): array
11
    {
12
        $documentRoots = self::extractDocumentRootByKey($inventory, ApacheServerNameCollector::COLLECTION_IDENTIFIER);
13
        $documentRoots = array_merge($documentRoots, self::extractDocumentRootByKey($inventory, NginxServerNameCollector::COLLECTION_IDENTIFIER));
14
15
        return array_unique($documentRoots);
16
    }
17
18
    private static function extractDocumentRootByKey(array $inventory, string $key): array
19
    {
20
        if (!array_key_exists($key, $inventory)
21
            || !is_array($inventory[$key])
22
        ) return [];
23
24
        $configs = $inventory[$key];
25
26
        $documentRoots = [];
27
28
        foreach ($configs as $config) {
29
            $documentRoots[$config[ApacheServerNameCollector::FIELD_SERVER_NAME]] = $config[ApacheServerNameCollector::FIELD_DOCUMENT_ROOT];
30
        }
31
32
        return $documentRoots;
33
    }
34
}