NotReservedValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 23
ccs 13
cts 13
cp 1
rs 10

1 Method

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