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

MinConstraint::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 2
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 not less then given.
10
 */
11 View Code Duplication
class MinConstraint 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 int
14
     */
15
    protected $min;
16
17
    /**
18
     * @var string
19
     */
20
    protected $message;
21
22
    /**
23
     * MinConstraint constructor.
24
     *
25
     * @param int $min
26
     * @param string $message
27
     */
28
    public function __construct($min, $message = null) {
29
        $this->min = $min;
30
        $this->message = $message;
31
    }
32
33
    /**
34
     * @param $value
35
     * @param IValidationData $data
36
     *
37
     * @return bool
38
     */
39
    public function check($value, IValidationData $data = null) {
40
        if (is_numeric($value)) {
41
            return $value >= $this->min;
42
        }
43
44
        return false;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getMessage() {
51
        if ($this->message !== null) {
52
            return $this->message;
53
        }
54
55
        return s(
56
            'Must not be smaller than "%s".', $this->min
57
        );
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function getOptions() {
64
        return [
65
            'min' => $this->min,
66
        ];
67
    }
68
}
69