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

OptionalBooleanValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 20
loc 20
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 9 9 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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