Passed
Push — master ( f0060e...f55da9 )
by Nils
03:53
created

WebsiteUtil::extractDomainsByKey()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 15
rs 10
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 WebsiteUtil
9
{
10
    public static function extractDomains(array $inventory): array
11
    {
12
        $domains = self::extractDomainsByKey($inventory, ApacheServerNameCollector::COLLECTION_IDENTIFIER);
13
        $domains = array_merge($domains, self::extractDomainsByKey($inventory, NginxServerNameCollector::COLLECTION_IDENTIFIER));
14
15
        return array_unique($domains);
16
    }
17
18
    private static function extractDomainsByKey(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
        $domains = [];
27
28
        foreach ($configs as $config) {
29
            $domains[] = $config[$key];
30
        }
31
32
        return $domains;
33
    }
34
}