MatchValidatorAnnotation   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 5
dl 0
loc 35
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 16 1
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Annotations\Validators;
15
16
use Maslosoft\Addendum\Helpers\ParamsExpander;
17
use Maslosoft\Mangan\Meta\ValidatorMeta;
18
use Maslosoft\Mangan\Validators\Proxy\RegexProxy;
19
use Maslosoft\Mangan\Validators\Traits\AllowEmpty;
20
21
/**
22
 * RegularExpressionValidator validates that the attribute value matches to the specified {@link pattern regular expression}.
23
 * You may invert the validation logic with help of the {@link not} property (available since 1.1.5).
24
 *
25
 * @author Qiang Xue <[email protected]>
26
 * @version $Id$
27
 * @package system.validators
28
 * @since 1.0
29
 */
30
class MatchValidatorAnnotation extends ValidatorAnnotation
31
{
32
33
	use AllowEmpty;
34
35
	/**
36
	 * @var string the regular expression to be matched with
37
	 */
38
	public $pattern = NULL;
39
40
	/**
41
	 * @var boolean whether to invert the validation logic. Defaults to false. If set to true,
42
	 * the regular expression defined via {@link pattern} should NOT match the attribute value.
43
	 * @since 1.1.5
44
	 * */
45
	public $not = false;
46
47
	public function init()
48
	{
49
		$this->proxy = RegexProxy::class;
50
		$this->getEntity()->validators[] = new ValidatorMeta(ParamsExpander::expand($this, [
51
					'pattern',
52
					'allowEmpty',
53
					'not',
54
					'message',
55
					'skipOnError',
56
					'on',
57
					'safe',
58
					'enableClientValidation',
59
					'except',
60
					'proxy'
61
		]));
62
	}
63
64
}
65