TokenIsNotUsedValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A validate() 6 6 2

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
declare(strict_types=1);
4
5
namespace Sylius\ShopApiPlugin\Validator;
6
7
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
8
use Symfony\Component\Validator\Constraint;
9
use Symfony\Component\Validator\ConstraintValidator;
10
11 View Code Duplication
final class TokenIsNotUsedValidator extends ConstraintValidator
12
{
13
    /**
14
     * @var OrderRepositoryInterface
15
     */
16
    private $orderRepository;
17
18
    /**
19
     * @param OrderRepositoryInterface $orderRepository
20
     */
21
    public function __construct(OrderRepositoryInterface $orderRepository)
22
    {
23
        $this->orderRepository = $orderRepository;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function validate($token, Constraint $constraint)
30
    {
31
        if (null !== $this->orderRepository->findOneBy(['tokenValue' => $token])) {
32
            $this->context->addViolation($constraint->message);
33
        }
34
    }
35
}
36