Completed
Push — master ( cd6f74...3785c8 )
by Konstantinos
03:56
created

NotBlankModelValidator::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6667
c 1
b 0
f 0
cc 3
eloc 4
nc 2
nop 2
1
<?php
2
/**
3
 * This file contains a NotBlank validator for single model types
4
 *
5
 * @license    https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3
6
 */
7
8
namespace BZIon\Form\Constraint;
9
10
use Symfony\Component\Validator\Constraint;
11
use Symfony\Component\Validator\Constraints\NotBlankValidator;
12
13
/**
14
 * Validator that makes sure a model is valid and values are not empty
15
 */
16
class NotBlankModelValidator extends NotBlankValidator
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function validate($value, Constraint $constraint)
22
    {
23
        if ($value instanceof \Model && !$value->isValid()) {
24
            // Let the parent class handle the invalid model
25
            $value = null;
26
        }
27
28
        parent::validate($value, $constraint);
29
    }
30
}
31