Code Duplication    Length = 25-29 lines in 3 locations

src/Validator/ChannelWithGivenCodeExistsValidator.php 1 location

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

src/Validator/ProductExistsValidator.php 1 location

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

src/Validator/SimpleProductValidator.php 1 location

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