StringSchema   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
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 62
ccs 22
cts 22
cp 1
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A minLength() 0 4 1
A __construct() 0 4 1
A pattern() 0 4 1
A nullable() 0 10 2
A maxLength() 0 4 1
A format() 0 4 1
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