ItemsKeyword   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 32
ccs 14
cts 14
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 25 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JsonSchema\Keyword;
6
7
use JsonSchema\Schema\SchemaInterface;
8
use Webmozart\Assert\Assert;
9
10
class ItemsKeyword extends AbstractKeyword
11
{
12
    const NAME = 'items';
13
14
    /**
15
     * @param SchemaInterface|SchemaInterface[]|null $items
16
     */
17 1
    public function __construct($items)
18
    {
19 1
        if (null === $items) {
20 1
            parent::__construct(static::NAME, null);
21
22 1
            return;
23
        }
24
25 1
        if (\is_array($items)) {
26 1
            Assert::isList($items);
27 1
            Assert::allIsInstanceOf($items, SchemaInterface::class);
28
29 1
            parent::__construct(static::NAME, array_map(
30 1
                function (SchemaInterface $schemaMetadata) {
31 1
                    return $schemaMetadata->toJsonSchema();
32 1
                },
33
                $items
34
            ));
35
36 1
            return;
37
        }
38
39 1
        Assert::isInstanceOf($items, SchemaInterface::class);
40
41 1
        parent::__construct(static::NAME, $items->toJsonSchema());
42 1
    }
43
}
44