Completed
Push — master ( 587f5e...7e0186 )
by Jean-Christophe
04:40
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
6
use Ubiquity\contents\validation\validators\ValidatorHasNotNull;
7
8
/**
9
 * Validates a string with a regex
10
 * Usage @validator("regex",pattern)
11
 * @author jcheron <[email protected]>
12
 * @version 1.0.0
13
 */
14
class RegexValidator extends ValidatorHasNotNull {
15
	protected $ref;
16
	protected $match;
17
	
18
	public function __construct(){
19
		$this->message="This value is not valid";
20
		$this->match=true;
21
	}
22
	
23 1
	public function validate($value) {
24 1
		parent::validate($value);
25 1
		$value = (string) $value;
26 1
		return !($this->match xor preg_match($this->ref, $value));
27
	}
28
	
29
	/**
30
	 * {@inheritDoc}
31
	 * @see \Ubiquity\contents\validation\validators\Validator::getParameters()
32
	 */
33 1
	public function getParameters(): array {
34 1
		return ["value"];
35
	}
36
}
37
38