SchemaMerger   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 30
ccs 18
cts 18
cp 1
rs 10
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B merge() 0 28 8
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Schema\Provider\Support;
6
7
use Cycle\Schema\Provider\Exception\DuplicateRoleException;
8
9
final class SchemaMerger
10
{
11 28
    public function merge(?array ...$parts): ?array
12
    {
13 28
        $schema = null;
14 28
        foreach ($parts as $part) {
15 23
            if ($part === null) {
16 6
                continue;
17
            }
18
19 20
            if ($schema === null) {
20 20
                $schema = $part;
21 20
                continue;
22
            }
23 10
            foreach ($part as $role => $body) {
24 10
                if (!\is_string($role)) {
25 1
                    $schema[] = $body;
26 1
                    continue;
27
                }
28 9
                if (\array_key_exists($role, $schema)) {
29 5
                    if ($schema[$role] === $body) {
30 2
                        continue;
31
                    }
32 3
                    throw new DuplicateRoleException($role);
33
                }
34 9
                $schema[$role] = $body;
35
            }
36
        }
37
38 25
        return $schema;
39
    }
40
}
41