NotNaughtyValidator::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 9.4285
cc 3
eloc 8
nc 3
nop 2
crap 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 1467
    public function validate($value, Constraint $constraint)
17
    {
18 1467
        if (empty(trim($value))) {
19 15
            return;
20
        }
21
22 1452
        $data = json_decode(
23 1452
            file_get_contents(__DIR__.'/../data/blns.json'),
24 484
            true
25 968
        );
26
27 1452
        if (in_array($value, $data, true)) {
28 1449
            $this->context->addViolation($constraint->message);
29 966
        }
30 1452
    }
31
}
32