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

WebsiteUtil   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractDomains() 0 6 1
A extractDomainsByKey() 0 15 4
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
}