Completed
Push — master ( 40f739...c90891 )
by Maxim
03:13
created

StringNode   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 13

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
c 2
b 0
f 0
lcom 1
cbo 13
dl 0
loc 99
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A min() 0 3 1
A max() 0 3 1
A length() 0 3 1
A email() 0 3 1
A url() 0 3 1
A alpha() 0 3 1
A alphanumeric() 0 3 1
A matches() 0 3 1
A allowed() 0 3 1
A forbidden() 0 3 1
1
<?php
2
3
namespace Weew\ConfigSchema\Nodes;
4
5
use Weew\ConfigSchema\IConfigSchema;
6
use Weew\Validator\Constraints\AllowedConstraint;
7
use Weew\Validator\Constraints\AlphaConstraint;
8
use Weew\Validator\Constraints\AlphaNumericConstraint;
9
use Weew\Validator\Constraints\EmailConstraint;
10
use Weew\Validator\Constraints\ForbiddenConstraint;
11
use Weew\Validator\Constraints\LengthConstraint;
12
use Weew\Validator\Constraints\MaxLengthConstraint;
13
use Weew\Validator\Constraints\MinLengthConstraint;
14
use Weew\Validator\Constraints\NotNullConstraint;
15
use Weew\Validator\Constraints\RegexConstraint;
16
use Weew\Validator\Constraints\StringConstraint;
17
use Weew\Validator\Constraints\UrlConstraint;
18
use Weew\Validator\IConstraint;
19
20
class StringNode extends Node implements IStringNode {
21
    /**
22
     * StringNode constructor.
23
     *
24
     * @param IConfigSchema $schema
25
     * @param string $key
26
     * @param string $message
27
     */
28
    public function __construct(IConfigSchema $schema, $key, $message = null) {
29
        parent::__construct($schema, $key);
30
31
        $this->constraints([
32
            new NotNullConstraint($message),
33
            new StringConstraint(),
34
        ]);
35
    }
36
37
    /**
38
     * @param int $min
39
     *
40
     * @return IStringNode
41
     */
42
    public function min($min) {
43
        return $this->constraint(new MinLengthConstraint($min));
44
    }
45
46
    /**
47
     * @param int $max
48
     *
49
     * @return IStringNode
50
     */
51
    public function max($max) {
52
        return $this->constraint(new MaxLengthConstraint($max));
53
    }
54
55
    /**
56
     * @param int $length
57
     *
58
     * @return IStringNode
59
     */
60
    public function length($length) {
61
        return $this->constraint(new LengthConstraint($length));
62
    }
63
64
    /**
65
     * @return IStringNode
66
     */
67
    public function email() {
68
        return $this->constraint(new EmailConstraint());
69
    }
70
71
    /**
72
     * @return IStringNode
73
     */
74
    public function url() {
75
        return $this->constraint(new UrlConstraint());
76
    }
77
78
    /**
79
     * @return IStringNode
80
     */
81
    public function alpha() {
82
        return $this->constraint(new AlphaConstraint());
83
    }
84
85
    /**
86
     * @return IStringNode
87
     */
88
    public function alphanumeric() {
89
        return $this->constraint(new AlphaNumericConstraint());
90
    }
91
92
    /**
93
     * @param string $regex
94
     *
95
     * @return IStringNode
96
     */
97
    public function matches($regex) {
98
        return $this->constraint(new RegexConstraint($regex));
99
    }
100
101
    /**
102
     * @param array $values
103
     *
104
     * @return IStringNode
105
     */
106
    public function allowed(array $values) {
107
        return $this->constraint(new AllowedConstraint($values));
108
    }
109
110
    /**
111
     * @param array $values
112
     *
113
     * @return IStringNode
114
     */
115
    public function forbidden(array $values) {
116
        return $this->constraint(new ForbiddenConstraint($values));
117
    }
118
}
119