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

ArrayNode::length()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 5
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Weew\ConfigSchema\Nodes;
4
5
use Weew\ConfigSchema\IConfigSchema;
6
use Weew\Validator\Constraints\AllowedSubsetConstraint;
7
use Weew\Validator\Constraints\ArrayConstraint;
8
use Weew\Validator\Constraints\ForbiddenSubsetConstraint;
9
use Weew\Validator\Constraints\LengthConstraint;
10
use Weew\Validator\Constraints\MaxLengthConstraint;
11
use Weew\Validator\Constraints\MinLengthConstraint;
12
use Weew\Validator\Constraints\NotNullConstraint;
13
14 View Code Duplication
class ArrayNode extends Node implements IArrayNode {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
    /**
16
     * ArrayNode constructor.
17
     *
18
     * @param IConfigSchema $schema
19
     * @param string $key
20
     * @param string $message
21
     */
22
    public function __construct(IConfigSchema $schema, $key, $message = null) {
23
        parent::__construct($schema, $key);
24
25
        $this->constraints([
26
            new NotNullConstraint($message),
27
            new ArrayConstraint(),
28
        ]);
29
    }
30
31
    /**
32
     * @param int $min
33
     *
34
     * @return IArrayNode
35
     */
36
    public function min($min) {
37
        return $this->constraint(
38
            new MinLengthConstraint($min)
39
        );
40
    }
41
42
    /**
43
     * @param int $max
44
     *
45
     * @return IArrayNode
46
     */
47
    public function max($max) {
48
        return $this->constraint(
49
            new MaxLengthConstraint($max)
50
        );
51
    }
52
53
    /**
54
     * @param int $length
55
     *
56
     * @return IArrayNode
57
     */
58
    public function length($length) {
59
        return $this->constraint(
60
            new LengthConstraint($length)
61
        );
62
    }
63
64
    /**
65
     * @param array $values
66
     *
67
     * @return IArrayNode
68
     */
69
    public function allowed(array $values) {
70
        return $this->constraint(
71
            new AllowedSubsetConstraint($values)
72
        );
73
    }
74
75
    /**
76
     * @param array $values
77
     *
78
     * @return IArrayNode
79
     */
80
    public function forbidden(array $values) {
81
        return $this->constraint(
82
            new ForbiddenSubsetConstraint($values)
83
        );
84
    }
85
}
86