Completed
Push — master ( f6e489...d5524c )
by Maxim
03:09
created

NullableConstraint   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 3 3 1
A check() 3 3 2
A getMessage() 7 7 2
A getOptions() 3 3 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\Validator\Constraints;
4
5
use Weew\Validator\IConstraint;
6
use Weew\Validator\IValidationData;
7
8
/**
9
 * This constraint is used to allow to tag a specific
10
 * subject as "optional". Validator will remove any errors
11
 * that occurred for the given subject if the subject value
12
 * is null or '' where this constraint has been applied.
13
 */
14 View Code Duplication
class NullableConstraint implements IConstraint {
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
     * @var string
17
     */
18
    protected $message;
19
20
    /**
21
     * FloatConstraint constructor.
22
     *
23
     * @param string $message
24
     */
25
    public function __construct($message = null) {
26
        $this->message = $message;
27
    }
28
29
    /**
30
     * @param $value
31
     * @param IValidationData $data
32
     *
33
     * @return bool
34
     */
35
    public function check($value, IValidationData $data = null) {
36
        return array_contains([null, ''], $value) ? false : true;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getMessage() {
43
        if ($this->message !== null) {
44
            return $this->message;
45
        }
46
47
        return 'May be null.';
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function getOptions() {
54
        return [];
55
    }
56
}
57