Completed
Push — master ( 306e90...0ddde3 )
by Maxim
02:42
created

ValueNode::nullable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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\ForbiddenConstraint;
8
use Weew\Validator\Constraints\NotNullConstraint;
9
use Weew\Validator\Constraints\NullableConstraint;
10
11
class ValueNode extends Node implements IValueNode {
12
    /**
13
     * ValueNode constructor.
14
     *
15
     * @param IConfigSchema $schema
16
     * @param string $key
17
     * @param string $message
18
     */
19
    public function __construct(IConfigSchema $schema, $key, $message = null) {
20
        parent::__construct($schema, $key);
21
22
        $this->constraint(
23
            new NotNullConstraint($message)
24
        );
25
    }
26
27
    /**
28
     * @param array $values
29
     *
30
     * @return IValueNode
31
     */
32
    public function allowed(array $values) {
33
        return $this->constraint(new AllowedConstraint($values));
34
    }
35
36
    /**
37
     * @param array $values
38
     *
39
     * @return IValueNode
40
     */
41
    public function forbidden(array $values) {
42
        return $this->constraint(new ForbiddenConstraint($values));
43
    }
44
45
    /**
46
     * @return IValueNode
47
     */
48
    public function nullable() {
49
        return $this->constraint(
50
            new NullableConstraint()
51
        );
52
    }
53
}
54