EqualsValidator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Ubiquity\contents\validation\validators\comparison;
4
5
use Ubiquity\contents\validation\validators\ValidatorHasNotNull;
6
7
/**
8
 * Ubiquity\contents\validation\validators\comparison$EqualsValidator
9
 * This class is part of Ubiquity
10
 *
11
 * @author jc
12
 * @version 1.0.0
13
 *
14
 */
15
class EqualsValidator extends ValidatorHasNotNull {
16
	protected $ref;
17
18
	public function __construct() {
19
		$this->message = 'This value should be equals to `{ref}`';
20
	}
21
22
	public function validate($value) {
23
		parent::validate ( $value );
24
		if ($this->notNull !== false) {
25
			return $value == $this->ref;
26
		}
27
		return true;
28
	}
29
30
	/**
31
	 *
32
	 * {@inheritdoc}
33
	 * @see \Ubiquity\contents\validation\validators\Validator::getParameters()
34
	 */
35
	public function getParameters(): array {
36
		return [ 'ref','value' ];
37
	}
38
39
	/**
40
	 *
41
	 * {@inheritdoc}
42
	 * @see \Ubiquity\contents\validation\validators\Validator::asUI()
43
	 */
44
	public function asUI(): array {
45
		return \array_merge_recursive ( parent::asUI (), [ 'rules' => [ [ 'type' => 'is','prompt' => $this->_getMessage (),'value' => $this->ref ] ] ] );
46
	}
47
}
48
49