Completed
Push — master ( 2c0e32...bddc44 )
by Emanuele
01:30
created

NotNaughtyValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 45.45%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 21
ccs 5
cts 11
cp 0.4545
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 15 3
1
<?php
2
3
namespace EmanueleMinotto\NaughtyValidator;
4
5
use Symfony\Component\Validator\Constraint;
6
use Symfony\Component\Validator\ConstraintValidator;
7
8
/**
9
 * Validator for naughty strings.
10
 */
11
class NotNaughtyValidator extends ConstraintValidator
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16 12
    public function validate($value, Constraint $constraint)
17
    {
18 12
        if (empty(trim($value))) {
19 6
            return;
20
        }
21
22 6
        $data = json_decode(
23 6
            file_get_contents(__DIR__.'/../data/blns.json'),
24
            true
25
        );
26
27
        if (in_array($value, $data, true)) {
28
            $this->context->addViolation($constraint->message);
29
        }
30
    }
31
}
32