StringSchema::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace JsonSchema\Schema;
4
5
use JsonSchema\Keyword\FormatKeyword;
6
use JsonSchema\Keyword\MaxLengthKeyword;
7
use JsonSchema\Keyword\MinLengthKeyword;
8
use JsonSchema\Keyword\PatternKeyword;
9
use JsonSchema\Keyword\TypeKeyword;
10
11
class StringSchema extends AbstractSchema
12
{
13 26
    public function __construct()
14
    {
15 26
        parent::__construct(
16 26
            new TypeKeyword('string')
17
        );
18 26
    }
19
20
    /**
21
     * @return static
22
     */
23 1
    public function nullable(bool $nullable = true): self
24
    {
25 1
        if (!$nullable) {
26 1
            return $this->with(
27 1
                new TypeKeyword('string')
28
            );
29
        }
30
31 1
        return $this->with(
32 1
            new TypeKeyword(['string', 'null'])
33
        );
34
    }
35
36
    /**
37
     * @return static
38
     */
39 1
    public function minLength(?int $minLength): self
40
    {
41 1
        return $this->with(
42 1
            new MinLengthKeyword($minLength)
43
        );
44
    }
45
46
    /**
47
     * @return static
48
     */
49 1
    public function maxLength(?int $maxLength): self
50
    {
51 1
        return $this->with(
52 1
            new MaxLengthKeyword($maxLength)
53
        );
54
    }
55
56
    /**
57
     * @return static
58
     */
59 1
    public function pattern(?string $pattern): self
60
    {
61 1
        return $this->with(
62 1
            new PatternKeyword($pattern)
63
        );
64
    }
65
66
    /**
67
     * @return static
68
     */
69 1
    public function format(?string $format): self
70
    {
71 1
        return $this->with(
72 1
            new FormatKeyword($format)
73
        );
74
    }
75
}
76