Passed
Push — master ( 0568ea...74fbac )
by Jean-Christophe
05:35
created

RangeValidator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 5
eloc 9
dl 0
loc 23
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 6 3
A __construct() 0 2 1
A getParameters() 0 2 1
1
<?php
2
3
namespace Ubiquity\contents\validation\validators\comparison;
4
5
use Ubiquity\contents\validation\validators\ValidatorHasNotNull;
6
7
/**
8
 * Check if a value is in a range
9
 *
10
 * Usage @validator("range",["min"=>minValue,"max"=>maxValue])
11
 *
12
 * @author jcheron <[email protected]>
13
 *
14
 */
15
class RangeValidator extends ValidatorHasNotNull {
16
	protected $min;
17
	protected $max;
18
19 1
	public function __construct() {
20 1
		$this->message = "This value should be between `{min}` and `{max}`";
21 1
	}
22
23 1
	public function validate($value) {
24 1
		parent::validate ( $value );
25 1
		if ($this->notNull !== false) {
26 1
			return $value >= $this->min && $value <= $this->max;
27
		}
28
		return true;
29
	}
30
31
	/**
32
	 *
33
	 * {@inheritdoc}
34
	 * @see \Ubiquity\contents\validation\validators\Validator::getParameters()
35
	 */
36 1
	public function getParameters(): array {
37 1
		return [ "min","max","value" ];
38
	}
39
}
40
41