Skip to content

Commit

Permalink
Validator refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Jun 9, 2021
1 parent 4fbf939 commit bcc3354
Showing 1 changed file with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,19 @@ public function validate($value, Constraint $constraint): void
$promotionCoupon === null ||
!$this->promotionCouponChecker->isEligible($cart, $promotionCoupon)
) {
$this->context->buildViolation('sylius.promotion_coupon.is_invalid')
->atPath('couponCode')
->addViolation()
;

return;
$this->addViolation('sylius.promotion_coupon.is_invalid', 'couponCode');
}

if (
!$this->promotionChecker->isEligible($cart, $promotionCoupon->getPromotion()) ||
!$promotion->getChannels()->contains($cart->getChannel())
) {
$this->context->buildViolation('sylius.promotion.is_invalid')
->atPath('couponCode')
->addViolation()
;
$this->addViolation('sylius.promotion.is_invalid', 'couponCode');
}
}

private function addViolation(string $message, string $path): void
{
$this->context->buildViolation($message)->atPath($path)->addViolation();
}
}

0 comments on commit bcc3354

Please sign in to comment.