for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\PromotionBundle\Validator;
use Sylius\Component\Promotion\Model\PromotionInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Webmozart\Assert\Assert;
/**
* @author Łukasz Chruściel <[email protected]>
class PromotionDateRangeValidator extends ConstraintValidator
{
* {@inheritdoc}
* @param mixed $value
* @param Constraint $constraint
public function validate($value, Constraint $constraint)
if (null === $value) {
return;
}
Assert::isInstanceOf(
$value,
PromotionInterface::class
);
if (null === $value->getStartsAt() || null === $value->getEndsAt()) {
if ($value->getStartsAt()->getTimestamp() > $value->getEndsAt()->getTimestamp()) {
$this->context->buildViolation($constraint->message)
->atPath('endsAt')
->addViolation();