MobileVNValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 19
loc 19
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 13 13 3

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
 * @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 MobileVNValidator 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 MobileVN) {
27
            throw new UnexpectedTypeException($constraint, MobileVN::class);
28
        }
29
30
        if (false === ConcreteValidator::mobileVN()->validate($value)) {
31
            $this->context->buildViolation($constraint->message)
32
                ->setParameter('{{ value }}', $this->formatValue($value))
33
                ->setCode(MobileVN::MOBILE_VN_ERROR)
34
                ->addViolation();
35
        }
36
    }
37
}
38