AbstractGeneratedByMiddleware   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 25
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getServerId() 0 23 5
1
<?php
2
declare(strict_types=1);
3
4
namespace Ctw\Middleware\GeneratedByMiddleware;
5
6
use Ctw\Middleware\AbstractMiddleware;
7
use Exception;
8
use Ramsey\Uuid\Uuid;
9
10
abstract class AbstractGeneratedByMiddleware extends AbstractMiddleware
11
{
12 4
    protected function getServerId(array $serverParams): string
13
    {
14 4
        $name = '';
15
16 4
        foreach (['SERVER_ADDR', 'SERVER_NAME'] as $key) {
17 4
            if (!isset($serverParams[$key])) {
18 2
                continue;
19
            }
20 2
            $value = (string) $serverParams[$key];
21 2
            $name  .= strtolower(trim($value));
22
        }
23
24 4
        if ('' === $name) {
25 2
            return '';
26
        }
27
28
        try {
29 2
            $ret = Uuid::uuid5(Uuid::NAMESPACE_URL, $name)->toString();
30
        } catch (Exception) {
31
            $ret = '';
32
        }
33
34 2
        return $ret;
35
    }
36
}
37