ItemsKeyword::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 25
ccs 14
cts 14
cp 1
crap 3
rs 9.8333
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