Completed
Push — master ( 11b317...37df4d )
by Lucas
09:27
created

OptionalBooleanValidator::validate()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 0
cts 9
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 2
nop 2
crap 20
1
<?php
2
/**
3
 * Validator for a strict boolean or null check (null because the value does not have to be set). The field is optional.
4
 */
5
6
namespace Graviton\RestBundle\Validator\Constraints;
7
8
use Symfony\Component\Validator\Constraint;
9
use Symfony\Component\Validator\ConstraintValidator;
10
11
/**
12
 * Validator for a strict boolean or null check.
13
 *
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18 View Code Duplication
class OptionalBooleanValidator extends ConstraintValidator
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    /**
21
     * Check strictly for boolean or null. (null because the value does not have to be set)
22
     *
23
     * @param string     $value      Input value
24
     * @param Constraint $constraint Constraint instance
25
     *
26
     * @return void
27
     */
28
    public function validate($value, Constraint $constraint)
29
    {
30
        if ($value !== true && $value !== false && $value !== '') {
31
            $this->context->addViolation(
32
                $constraint->message,
33
                array('%string%' => $value)
34
            );
35
        }
36
    }
37
}
38