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

IsBooleanValidator::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
ccs 4
cts 5
cp 0.8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.032
1
<?php
2
3
namespace Ubiquity\contents\validation\validators\basic;
4
5
use Ubiquity\utils\base\UString;
6
use Ubiquity\contents\validation\validators\ValidatorHasNotNull;
7
8
class IsBooleanValidator extends ValidatorHasNotNull {
9
10 2
	public function __construct() {
11 2
		$this->message = "This value should be a boolean";
12 2
	}
13
14 2
	public function validate($value) {
15 2
		parent::validate ( $value );
16 2
		if ($this->notNull !== false) {
17 2
			return UString::isBooleanStr ( $value );
18
		}
19
		return true;
20
	}
21
22
	/**
23
	 *
24
	 * {@inheritdoc}
25
	 * @see \Ubiquity\contents\validation\validators\Validator::getParameters()
26
	 */
27 1
	public function getParameters(): array {
28 1
		return [ "value" ];
29
	}
30
}
31
32