Passed
Push — master ( 2dffc4...9bc131 )
by Alexander
02:20
created

SchemaMerger   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B merge() 0 24 8
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Cycle\Schema\Provider\Support;
6
7
use Yiisoft\Yii\Cycle\Exception\DuplicateRoleException;
8
9
final class SchemaMerger
10
{
11 27
    public function merge(?array ...$parts): ?array
12
    {
13 27
        $schema = null;
14 27
        foreach ($parts as $part) {
15 21
            if (empty($part)) {
16 6
                $schema ??= $part;
17 6
                continue;
18
            }
19 17
            foreach ($part as $role => $body) {
20 17
                if (!is_string($role)) {
21 1
                    $schema[] = $body;
22 1
                    continue;
23
                }
24 16
                if ($schema !== null && array_key_exists($role, $schema)) {
0 ignored issues
show
Bug introduced by
$schema of type null is incompatible with the type array expected by parameter $search of array_key_exists(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
                if ($schema !== null && array_key_exists($role, /** @scrutinizer ignore-type */ $schema)) {
Loading history...
25 5
                    if ($schema[$role] === $body) {
26 2
                        continue;
27
                    }
28 3
                    throw new DuplicateRoleException($role);
29
                }
30 16
                $schema[$role] = $body;
31
            }
32
        }
33
34 24
        return $schema;
35
    }
36
}
37