Passed
Pull Request — master (#86)
by Aleksei
04:24 queued 41s
created

SchemaMerger   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 13
c 1
b 0
f 0
dl 0
loc 22
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B merge() 0 20 7
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 21
    public function merge(?array ...$parts): ?array
12
    {
13 21
        $schema = null;
14 21
        foreach ($parts as $part) {
15 15
            if (empty($part)) {
16 3
                $schema ??= $part;
17 3
                continue;
18
            }
19 13
            foreach ($part as $role => $body) {
20 13
                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

20
                if ($schema !== null && array_key_exists($role, /** @scrutinizer ignore-type */ $schema)) {
Loading history...
21 3
                    if ($schema[$role] === $body) {
22 1
                        continue;
23
                    }
24 2
                    throw new DuplicateRoleException($role);
25
                }
26 13
                $schema[$role] = $body;
27
            }
28
        }
29
30 19
        return $schema;
31
    }
32
}
33