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

Filled   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 17
rs 10
ccs 5
cts 5
cp 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 8 2
A getMetadata() 0 5 1
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