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

NotBlankModelValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 15
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 9 3
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