BooleanValidatorAnnotation   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 17 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\Annotations\Validators\ValidatorAnnotation;
18
use Maslosoft\Mangan\Meta\ValidatorMeta;
19
use Maslosoft\Mangan\Validators\Proxy\BooleanProxy;
20
use Maslosoft\Mangan\Validators\Traits\AllowEmpty;
21
use Maslosoft\Mangan\Validators\Traits\Strict;
22
23
/**
24
 * BooleanValidator validates that the attribute value is either {@link trueValue}  or {@link falseValue}.
25
 *
26
 * When using the {@link message} property to define a custom error message, the message
27
 * may contain additional placeholders that will be replaced with the actual content. In addition
28
 * to the "{attribute}" placeholder, recognized by all validators (see {@link Validator}),
29
 * BooleanValidator allows for the following placeholders to be specified:
30
 * <ul>
31
 * <li>{true}: replaced with value representing the true status {@link trueValue}.</li>
32
 * <li>{false}: replaced with value representing the false status {@link falseValue}.</li>
33
 * </ul>
34
 *
35
 * @author Qiang Xue <[email protected]>
36
 * @version $Id$
37
 * @package system.validators
38
 */
39
class BooleanValidatorAnnotation extends ValidatorAnnotation
40
{
41
42
	use Strict,
43
	  AllowEmpty;
44
45
	/**
46
	 * @var mixed the value representing true status. Defaults to '1'.
47
	 */
48
	public $trueValue = '1';
49
50
	/**
51
	 * @var mixed the value representing false status. Defaults to '0'.
52
	 */
53
	public $falseValue = '0';
54
55
	public function init()
56
	{
57
		$this->proxy = BooleanProxy::class;
58
		$this->getEntity()->validators[] = new ValidatorMeta(ParamsExpander::expand($this, [
59
					'trueValue',
60
					'falseValue',
61
					'strict',
62
					'allowEmpty',
63
					'message',
64
					'skipOnError',
65
					'on',
66
					'safe',
67
					'enableClientValidation',
68
					'except',
69
					'proxy'
70
		]));
71
	}
72
73
}
74