Completed
Push — master ( 632b2b...e22e45 )
by Peter
08:08
created

ImmutableValidatorAnnotation   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 19 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\ImmutableProxy;
19
use Maslosoft\Mangan\Validators\Traits\AllowEmpty;
20
use Maslosoft\Mangan\Validators\Traits\When;
21
22
/**
23
 * Immutable Validator
24
 *
25
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
26
 */
27
class ImmutableValidatorAnnotation extends ValidatorAnnotation
28
{
29
30
	use AllowEmpty,
31
	  When;
32
33
	/**
34
	 * Against which attribute to validate, defaults to current
35
	 * @var string
36
	 */
37
	public $against = '';
38
39
	/**
40
	 * @var string the ActiveRecord class name that should be used to
41
	 * look for the attribute value being validated. Defaults to null, meaning using
42
	 * the class of the object currently being validated.
43
	 * You may use path alias to reference a class name here.
44
	 * @see attributeName
45
	 * @since 1.0.8
46
	 */
47
	public $className;
48
49
	/**
50
	 * @var string the ActiveRecord class attribute name that should be
51
	 * used to look for the attribute value being validated. Defaults to null,
52
	 * meaning using the name of the attribute being validated.
53
	 * @see className
54
	 * @since 1.0.8
55
	 */
56
	public $attributeName;
57
58
	/**
59
	 * @var array additional query criteria. This will be combined with the condition
60
	 * that checks if the attribute value exists in the corresponding table column.
61
	 * This array will be used to instantiate a {@link Criteria} object.
62
	 * @since 1.0.8
63
	 */
64
	public $criteria = [];
65
66
	/**
67
	 * @var string the user-defined error message. The placeholders "{attribute}" and "{value}"
68
	 * are recognized, which will be replaced with the actual attribute name and value, respectively.
69
	 */
70
	public $message;
71
72 2
	public function init()
73
	{
74 2
		$this->proxy = ImmutableProxy::class;
75 2
		$this->getEntity()->validators[] = new ValidatorMeta(ParamsExpander::expand($this, [
76 2
					'allowEmpty',
77
					'when',
78
					'against',
79
					'className',
80
					'attributeName',
81
					'criteria',
82
					'message',
83
					'skipOnError',
84
					'on',
85
					'safe',
86
					'enableClientValidation',
87
					'except',
88
					'proxy'
89
		]));
90 2
	}
91
92
}
93