Completed
Push — master ( 46ca35...9cf9e5 )
by Maxim
03:19
created

ArrayConstraint   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
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 1
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
 * Check if the value is an array.
10
 */
11 View Code Duplication
class ArrayConstraint 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...
12
    /**
13
     * @var string
14
     */
15
    protected $message;
16
17
    /**
18
     * ArrayConstraint constructor.
19
     *
20
     * @param string $message
21
     */
22
    public function __construct($message = null) {
23
        $this->message = $message;
24
    }
25
26
    /**
27
     * @param $value
28
     * @param IValidationData $data
29
     *
30
     * @return bool
31
     */
32
    public function check($value, IValidationData $data = null) {
33
        return is_array($value);
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    public function getMessage() {
40
        if ($this->message !== null) {
41
            return $this->message;
42
        }
43
44
        return 'Must be an array.';
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function getOptions() {
51
        return [];
52
    }
53
}
54