Code Duplication    Length = 33-33 lines in 2 locations

src/Validator/ConfigurableProductValidator.php 1 location

@@ 11-43 (lines=33) @@
8
use Symfony\Component\Validator\Constraint;
9
use Symfony\Component\Validator\ConstraintValidator;
10
11
final class ConfigurableProductValidator 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) {
32
            return;
33
        }
34
35
        $product = $this->productRepository->findOneByCode($productCode);
36
37
        if (null === $product || $product->isConfigurable()) {
38
            return;
39
        }
40
41
        $this->context->addViolation($constraint->message);
42
    }
43
}
44

src/Validator/SimpleProductValidator.php 1 location

@@ 11-43 (lines=33) @@
8
use Symfony\Component\Validator\Constraint;
9
use Symfony\Component\Validator\ConstraintValidator;
10
11
final class SimpleProductValidator 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) {
32
            return;
33
        }
34
35
        $product = $this->productRepository->findOneByCode($productCode);
36
37
        if (null === $product || $product->isSimple()) {
38
            return;
39
        }
40
41
        $this->context->addViolation($constraint->message);
42
    }
43
}
44