Completed
Push — master ( 587f5e...7e0186 )
by Jean-Christophe
04:40
created

IdValidator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 8
eloc 19
dl 0
loc 40
ccs 14
cts 21
cp 0.6667
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setParams() 0 4 2
A __construct() 0 5 1
A getParameters() 0 2 1
A validate() 0 13 4
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 ValidatorMultiple {
10
	protected $autoinc;
11 1
	public function __construct(){
12 1
		parent::__construct();
13 1
		$this->message=array_merge($this->message,[
14 1
				"positive"=>"This value must be positive",
15
				"type"=>"This value must be an integer"
16
		]);
17 1
	}
18
	
19 1
	public function validate($value) {
20 1
		if (!parent::validate($value)) {
21 1
			return false;
22
		}
23
		if($value!=(int)$value){
24
			$this->violation="type";
25
			return false;
26
		}
27
		if($value<=0){
28
			$this->violation="positive";
29
			return false;
30
		}
31
		return true;
32
	}
33
	
34
	/**
35
	 * {@inheritDoc}
36
	 * @see \Ubiquity\contents\validation\validators\Validator::getParameters()
37
	 */
38 1
	public function getParameters(): array {
39 1
		return ["value"];
40
	}
41
	/**
42
	 * {@inheritDoc}
43
	 * @see \Ubiquity\contents\validation\validators\Validator::setParams()
44
	 */
45 1
	protected function setParams(array $params) {
46 1
		parent::setParams($params);
47 1
		if($this->autoinc===true){
48 1
			$this->notNull=false;
49
		}
50 1
	}
51
52
	
53
	
54
55
}
56
57