Completed
Push — master ( 94ddbb...e5219e )
by Jean-Christophe
04:25
created

IdValidator::validate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5.024

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 13
ccs 6
cts 10
cp 0.6
rs 9.9666
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 5.024
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 3
	public function __construct(){
12 3
		parent::__construct();
13 3
		$this->message=array_merge($this->message,[
14 3
				"positive"=>"This value must be positive",
15
				"type"=>"This value must be an integer"
16
		]);
17 3
	}
18
	
19 3
	public function validate($value) {
20 3
		if (!parent::validate($value)) {
21 1
			return false;
22
		}
23 2
		if($value!=(int)$value){
24
			$this->violation="type";
25
			return false;
26
		}
27 2
		if($value<=0){
28
			$this->violation="positive";
29
			return false;
30
		}
31 2
		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 3
	protected function setParams(array $params) {
46 3
		parent::setParams($params);
47 3
		if($this->autoinc===true){
48 3
			$this->notNull=false;
49
		}
50 3
	}
51
52
	
53
	
54
55
}
56
57