AbstractKeyword::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 18
ccs 7
cts 7
cp 1
crap 1
rs 9.7998
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JsonSchema\Keyword;
6
7
use Webmozart\Assert\Assert;
8
9
abstract class AbstractKeyword implements KeywordInterface
10
{
11
    private string $key;
12
13
    /**
14
     * @var mixed[]|bool|float|int|object|string|null
15
     */
16
    private $value;
17
18
    private bool $supportsNullValue;
19
20
    /**
21
     * @param mixed[]|bool|float|int|object|string|null $value
22
     */
23 200
    public function __construct(string $key, $value, bool $supportsNullValue = false)
24
    {
25 200
        Assert::stringNotEmpty($key);
26 200
        Assert::nullOrOneOf(\gettype($value), [
27 200
            'array',
28
            'boolean',
29
            'float',
30
            'double',
31
            'real',
32
            'integer',
33
            'object',
34
            'string',
35
            'NULL',
36
        ]);
37
38 200
        $this->key = $key;
39 200
        $this->value = $value;
40 200
        $this->supportsNullValue = $supportsNullValue;
41 200
    }
42
43 200
    public function getKey(): string
44
    {
45 200
        return $this->key;
46
    }
47
48 200
    public function getValue()
49
    {
50 200
        return $this->value;
51
    }
52
53 200
    public function supportsNullValue(): bool
54
    {
55 200
        return $this->supportsNullValue;
56
    }
57
}
58