<commit_before><?php
/*
 * WellCommerce Open-Source E-Commerce Platform
 * 
 * This file is part of the WellCommerce package.
 *
 * (c) <NAME> <<EMAIL>>
 * 
 * For the full copyright and license information,
 * please view the LICENSE file that was distributed with this source code.
 */

namespace WellCommerce\Bundle\CouponBundle\Checker;

use WellCommerce\Bundle\CouponBundle\Entity\CouponInterface;
use WellCommerce\Bundle\OrderBundle\Repository\OrderRepositoryInterface;

/**
 * Class CouponChecker
 *
 * @author  <NAME> <<EMAIL>>
 */
final class CouponChecker implements CouponCheckerInterface
{
    /**
     * @var string
     */
    private $error = '';

    /**
     * {@inheritdoc}
     */
    public function isValid(CouponInterface $coupon = null) : bool
    {
        if (null === $coupon) {
            $this->error = 'coupon.error.not_found';

            return false;
        }

        if (false === $this->isStartDateValid($coupon)) {
            $this->error = 'coupon.error.future_coupon';

            return false;
        }

        if (false === $this->isNotExpired($coupon)) {
            $this->error = 'coupon.error.coupon_expired';

            return false;
        }

        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function getError() : string
    {
        return $this->error;
    }

    /**
     * Checks whether the coupon's start date is valid
     *
     * @param CouponInterface $coupon
     *
     * @return bool
     */
    private function isStartDateValid(CouponInterface $coupon) : bool
    {
        $now             = new \DateTime();
        $couponStartDate = $coupon->getValidFrom();

        if ($couponStartDate instanceof \DateTime) {
            return $now >= $couponStartDate;
        }

        return true;
    }

    /**
     * Checks whether the coupon is not expired
     *
     * @param CouponInterface $coupon
     *
     * @return bool
     */
    private function isNotExpired(CouponInterface $coupon) : bool
    {
        $now           = new \DateTime();
        $couponEndDate = $coupon->getValidTo();

        if ($couponEndDate instanceof \DateTime) {
            return $now <= $couponEndDate;
        }

        return true;
    }
}
<commit_msg>CS fixes<commit_after><?php
/*
 * WellCommerce Open-Source E-Commerce Platform
 * 
 * This file is part of the WellCommerce package.
 *
 * (c) <NAME> <<EMAIL>>
 * 
 * For the full copyright and license information,
 * please view the LICENSE file that was distributed with this source code.
 */

namespace WellCommerce\Bundle\CouponBundle\Checker;

use WellCommerce\Bundle\CouponBundle\Entity\CouponInterface;

/**
 * Class CouponChecker
 *
 * @author  <NAME> <<EMAIL>>
 */
final class CouponChecker implements CouponCheckerInterface
{
    /**
     * @var string
     */
    private $error = '';

    /**
     * {@inheritdoc}
     */
    public function isValid(CouponInterface $coupon = null) : bool
    {
        if (null === $coupon) {
            $this->error = 'coupon.error.not_found';

            return false;
        }

        if (false === $this->isStartDateValid($coupon)) {
            $this->error = 'coupon.error.future_coupon';

            return false;
        }

        if (false === $this->isNotExpired($coupon)) {
            $this->error = 'coupon.error.coupon_expired';

            return false;
        }

        return true;
    }

    /**
     * {@inheritdoc}
     */
    public function getError() : string
    {
        return $this->error;
    }

    /**
     * Checks whether the coupon's start date is valid
     *
     * @param CouponInterface $coupon
     *
     * @return bool
     */
    private function isStartDateValid(CouponInterface $coupon) : bool
    {
        $now             = new \DateTime();
        $couponStartDate = $coupon->getValidFrom();

        if ($couponStartDate instanceof \DateTime) {
            return $now >= $couponStartDate;
        }

        return true;
    }

    /**
     * Checks whether the coupon is not expired
     *
     * @param CouponInterface $coupon
     *
     * @return bool
     */
    private function isNotExpired(CouponInterface $coupon) : bool
    {
        $now           = new \DateTime();
        $couponEndDate = $coupon->getValidTo();

        if ($couponEndDate instanceof \DateTime) {
            return $now <= $couponEndDate;
        }

        return true;
    }
}

{'fraction_non_alphanumeric': 0.118140589569161, 'fraction_numerical': 0.0, 'mean_word_length': 2.0047683923705724, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4790537', 'n_tokens_mistral': 1326, 'n_tokens_neox': 1346, 'n_words': 309}