IdVNValidator::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
c 0
b 0
f 0
rs 9.8333
cc 3
nc 3
nop 2
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/symfony-validation
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [MIT](http://www.opensource.org/licenses/MIT)
6
 */
7
8
namespace PHPViet\Symfony\Validation\Constraints;
9
10
use Symfony\Component\Validator\Constraint;
11
use Symfony\Component\Validator\ConstraintValidator;
12
use PHPViet\Validation\Validator as ConcreteValidator;
13
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
14
15
/**
16
 * @author Vuong Minh <[email protected]>
17
 * @since 1.0.0
18
 */
19 View Code Duplication
class IdVNValidator 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...
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function validate($value, Constraint $constraint): void
25
    {
26
        if (! $constraint instanceof IdVN) {
27
            throw new UnexpectedTypeException($constraint, IdVN::class);
28
        }
29
30
        if (false === ConcreteValidator::idVN()->validate($value)) {
31
            $this->context->buildViolation($constraint->message)
32
                ->setParameter('{{ value }}', $this->formatValue($value))
33
                ->setCode(IdVN::ID_VN_ERROR)
34
                ->addViolation();
35
        }
36
    }
37
}
38