Completed
Push — master ( f8bd36...f2dc96 )
by Jean-Christophe
01:33
created

IdValidator::validate()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.3888
c 0
b 0
f 0
cc 5
nc 5
nop 1
1
<?php
2
3
namespace Ubiquity\contents\validation\validators\multiples;
4
5
/**
6
 * Validate int identifiers (notNull positive integer)
7
 * @author jc
8
 */
9
class IdValidator extends ValidatorMultipleNotNull {
10
	
11
	public function __construct(){
12
		parent::__construct();
13
		$this->message=array_merge($this->message,[
14
				"positive"=>"This value must be positive",
15
				"type"=>"This value must be an integer"
16
		]);
17
	}
18
	
19
	public function validate($value) {
20
		if (!parent::validate($value)) {
21
			return false;
22
		}
23
		if(null==$value){
24
			return true;
25
		}
26
		if(!is_integer($value)){
27
			$this->violation="type";
28
			return false;
29
		}
30
		if($value<=0){
31
			$this->violation="positive";
32
			return false;
33
		}
34
		return true;
35
	}
36
	
37
	/**
38
	 * {@inheritDoc}
39
	 * @see \Ubiquity\contents\validation\validators\Validator::getParameters()
40
	 */
41
	public function getParameters(): array {
42
		return ["value"];
43
	}
44
45
}
46
47