Passed
Push — master ( ea62c3...cd2ef0 )
by Bruno
09:11
created

Filled::getMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
ccs 0
cts 0
cp 0
crap 2
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Validator;
4
5
use Formularium\Exception\ValidatorException;
6
use Formularium\Field;
7
use Formularium\Model;
8
use Formularium\ValidatorInterface;
9
use Formularium\ValidatorMetadata;
10
11
/**
12
 * May not be present, but if it is must not be empty.
13
 */
14
class Filled implements ValidatorInterface
15 3
{
16
    public function validate($value, array $options = [], Model $model = null)
17
    {
18 3
        // must be filled?
19 3
        if (empty($value)) {
20 1
            throw new ValidatorException("Field  must be filled");
21
        }
22
23 3
        return $value;
24
    }
25
26
    public function getMetadata(): ValidatorMetadata
27
    {
28
        return new ValidatorMetadata(
29
            __CLASS__,
30
            "Field may not be present, but if it is must not be empty."
31
        );
32
    }
33
}
34