Filled::getMetadata()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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