NumericNode::nullable()   A
last analyzed

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 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\MaxConstraint;
9
use Weew\Validator\Constraints\MinConstraint;
10
use Weew\Validator\Constraints\NotNullConstraint;
11
use Weew\Validator\Constraints\NullableConstraint;
12
use Weew\Validator\Constraints\NumericConstraint;
13
14 View Code Duplication
class NumericNode extends Node implements INumericNode {
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
     * NumericNode 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 NumericConstraint(),
28
        ]);
29
    }
30
31
    /**
32
     * @param int $min
33
     *
34
     * @return INumericNode
35
     */
36
    public function min($min) {
37
        return $this->constraint(
38
            new MinConstraint($min)
39
        );
40
    }
41
42
    /**
43
     * @param int $max
44
     *
45
     * @return INumericNode
46
     */
47
    public function max($max) {
48
        return $this->constraint(
49
            new MaxConstraint($max)
50
        );
51
    }
52
53
    /**
54
     * @param array $values
55
     *
56
     * @return INumericNode
57
     */
58
    public function allowed(array $values) {
59
        return $this->constraint(
60
            new AllowedConstraint($values)
61
        );
62
    }
63
64
    /**
65
     * @param array $values
66
     *
67
     * @return INumericNode
68
     */
69
    public function forbidden(array $values) {
70
        return $this->constraint(
71
            new ForbiddenConstraint($values)
72
        );
73
    }
74
75
    /**
76
     * @return INumericNode
77
     */
78
    public function nullable() {
79
        return $this->constraint(
80
            new NullableConstraint()
81
        );
82
    }
83
}
84