Passed
Push — master ( 0568ea...74fbac )
by Jean-Christophe
05:35
created

RegexValidator::getParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ubiquity\contents\validation\validators\strings;
4
5
use Ubiquity\contents\validation\validators\ValidatorHasNotNull;
6
7
/**
8
 * Validates a string with a regex
9
 * Usage @validator("regex",pattern)
10
 *
11
 * @author jcheron <[email protected]>
12
 * @version 1.0.0
13
 */
14
class RegexValidator extends ValidatorHasNotNull {
15
	protected $ref;
16
	protected $match;
17
18 1
	public function __construct() {
19 1
		$this->message = "This value is not valid";
20 1
		$this->match = true;
21 1
	}
22
23 3
	public function validate($value) {
24 3
		parent::validate ( $value );
25 3
		if ($this->notNull !== false) {
26 3
			$value = ( string ) $value;
27 3
			return ! ($this->match xor preg_match ( $this->ref, $value ));
28
		}
29
		return true;
30
	}
31
32
	/**
33
	 *
34
	 * {@inheritdoc}
35
	 * @see \Ubiquity\contents\validation\validators\Validator::getParameters()
36
	 */
37 3
	public function getParameters(): array {
38 3
		return [ "value" ];
39
	}
40
}
41
42