DependentSchemasKeyword   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 28 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JsonSchema\Keyword;
6
7
use JsonSchema\Property\PropertyInterface;
8
use Webmozart\Assert\Assert;
9
10
class DependentSchemasKeyword extends AbstractKeyword
11
{
12
    const NAME = 'dependentSchemas';
13
14
    /**
15
     * @param PropertyInterface[]|null $properties
16
     */
17 1
    public function __construct(?array $properties)
18
    {
19 1
        if (null === $properties) {
0 ignored issues
show
introduced by
The condition null === $properties is always false.
Loading history...
20 1
            parent::__construct(static::NAME, null);
21
22 1
            return;
23
        }
24
25 1
        Assert::isNonEmptyList($properties);
26 1
        Assert::allIsInstanceOf($properties, PropertyInterface::class);
27
28 1
        $dependentSchemas = [];
29
30 1
        foreach ($properties as $property) {
31 1
            $propertyDependentSchema = $property->getDependentSchema();
32
33 1
            if (null !== $propertyDependentSchema) {
34 1
                $dependentSchemas[$property->getName()] = $propertyDependentSchema;
35
            }
36
        }
37
38 1
        if (0 === \count($dependentSchemas)) {
39 1
            parent::__construct(static::NAME, null);
40
41 1
            return;
42
        }
43
44 1
        parent::__construct(static::NAME, (object) $dependentSchemas);
45 1
    }
46
}
47