Total Complexity | 8 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Coverage | 80.95% |
Changes | 0 |
1 | <?php |
||
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) { |
|
49 | } |
||
50 | 3 | } |
|
51 | |||
52 | |||
57 |