NumericNode   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 1
cbo 8
dl 70
loc 70
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 1
A min() 5 5 1
A max() 5 5 1
A allowed() 5 5 1
A forbidden() 5 5 1
A nullable() 5 5 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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