Passed
Push — master ( f360f0...1bc594 )
by Bruno
06:10
created

Filled::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 10
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
10
/**
11
 * May not be present, but if it is must not be empty.
12
 */
13
class Filled implements ValidatorInterface
14
{
15 3
    public function validate($value, Field $field, Model $model = null)
16
    {
17
        // must be filled?
18 3
        if ($field->getValidators()[self::class] ?? false) {
19 3
            if (empty($value)) {
20 1
                throw new ValidatorException("Field {$field->getName()} must be filled");
21
            }
22
        }
23 3
        return $value;
24
    }
25
}
26