Conditions | 5 |
Paths | 4 |
Total Lines | 19 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
41 | public function validate($value, Constraint $constraint) |
||
42 | { |
||
43 | if (!$value instanceof ProductInterface) { |
||
44 | throw new UnexpectedTypeException($value, ProductInterface::class); |
||
45 | } |
||
46 | |||
47 | if (!$value->isSimple()) { |
||
48 | return; |
||
49 | } |
||
50 | |||
51 | $existingProductVariant = $this->productVariantRepository->findOneBy(['code' => $value->getCode()]); |
||
52 | |||
53 | if (null !== $existingProductVariant && $existingProductVariant->getProduct()->getId() !== $value->getId()) { |
||
54 | $this->context->buildViolation($constraint->message) |
||
55 | ->atPath('code') |
||
56 | ->addViolation() |
||
57 | ; |
||
58 | } |
||
59 | } |
||
60 | } |
||
61 |
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.