Passed
Pull Request — master (#86)
by Aleksei
02:36
created

MergeSchemaProvider::read()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 7.2269

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 19
ccs 10
cts 12
cp 0.8333
rs 8.8333
cc 7
nc 7
nop 1
crap 7.2269
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Cycle\Schema\Provider\Support;
6
7
use RuntimeException;
8
use Yiisoft\Yii\Cycle\Schema\SchemaProviderInterface;
9
10
/**
11
 * A class for working with a group of schema providers.
12
 * Parts of the schema are read from all providers and merged into one.
13
 */
14
final class MergeSchemaProvider extends BaseProviderCollector
15
{
16
    protected const IS_SEQUENCE_PIPELINE = false;
17
18 4
    public function read(?SchemaProviderInterface $nextProvider = null): ?array
19
    {
20 4
        if ($this->providers === null) {
21
            throw new RuntimeException(self::class . ' is not configured.');
22
        }
23 4
        if ($this->providers->count() === 0) {
24 2
            return $nextProvider === null ? null : $nextProvider->read();
25
        }
26 3
        $parts = [];
27 3
        foreach ($this->providers as $provider) {
28 3
            $parts[] = $provider->read();
29
        }
30
31 3
        $schema = (new SchemaMerger())->merge(...$parts);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $schema is correct as new Yiisoft\Yii\Cycle\Sc...Merger()->merge($parts) targeting Yiisoft\Yii\Cycle\Schema...t\SchemaMerger::merge() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
32
33 2
        if ($schema !== null || $nextProvider === null) {
34 2
            return $schema;
35
        }
36
        return  $nextProvider->read();
37
    }
38
}
39