BooleanConstraint::getOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 3
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 3
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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 a boolean.
10
 */
11 View Code Duplication
class BooleanConstraint 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
     * BooleanConstraint 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_bool($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 a boolean.';
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    public function getOptions() {
51
        return [];
52
    }
53
}
54