Passed
Push — master ( bd3cb9...127ddb )
by Jean-Christophe
17:45
created

ValidatorHasNotNull::asUI()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 0
crap 2.0625
1
<?php
2
3
namespace Ubiquity\contents\validation\validators;
4
5
use Ubiquity\exceptions\ValidatorException;
6
use Ubiquity\utils\base\UString;
7
8
abstract class ValidatorHasNotNull extends Validator implements HasNotNullInterface {
9
	protected $notNull;
10
11 2
	public function validate($value) {
12 2
		if ($this->notNull !== false && (null === $value || '' === $value)) {
13 2
			return;
14
		}
15 1
		if ($this->notNull === true && ! UString::isValid ( $value )) {
16
			throw new ValidatorException ( 'This value can not be converted to string' );
17
		}
18
	}
19
20 1
	public function asUI(): array {
21 1
		if ($this->notNull) {
22 1
			return [ 'rules' => [ 'empty' ] ];
23
		}
24
		return [ ];
25
	}
26
}
27
28