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

ValueNode   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 4
dl 0
loc 43
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A allowed() 0 3 1
A forbidden() 0 3 1
A nullable() 0 5 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\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