Code Duplication    Length = 25-25 lines in 2 locations

src/Validator/ChannelExistsValidator.php 1 location

@@ 11-35 (lines=25) @@
8
use Symfony\Component\Validator\Constraint;
9
use Symfony\Component\Validator\ConstraintValidator;
10
11
final class ChannelExistsValidator extends ConstraintValidator
12
{
13
    /**
14
     * @var ChannelRepositoryInterface
15
     */
16
    private $channelRepository;
17
18
    /**
19
     * @param ChannelRepositoryInterface $channelRepository
20
     */
21
    public function __construct(ChannelRepositoryInterface $channelRepository)
22
    {
23
        $this->channelRepository = $channelRepository;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function validate($token, Constraint $constraint)
30
    {
31
        if (null === $token || null === $this->channelRepository->findOneByCode($token)) {
32
            $this->context->addViolation($constraint->message);
33
        }
34
    }
35
}
36

src/Validator/ProductExistsValidator.php 1 location

@@ 11-35 (lines=25) @@
8
use Symfony\Component\Validator\Constraint;
9
use Symfony\Component\Validator\ConstraintValidator;
10
11
final class ProductExistsValidator extends ConstraintValidator
12
{
13
    /**
14
     * @var ProductRepositoryInterface
15
     */
16
    private $productRepository;
17
18
    /**
19
     * @param ProductRepositoryInterface $productRepository
20
     */
21
    public function __construct(ProductRepositoryInterface $productRepository)
22
    {
23
        $this->productRepository = $productRepository;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function validate($productCode, Constraint $constraint)
30
    {
31
        if (null === $productCode || null === $this->productRepository->findOneByCode($productCode)) {
32
            $this->context->addViolation($constraint->message);
33
        }
34
    }
35
}
36