Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Add Function to Check Voucher Validity #51

Merged
merged 13 commits into from
Dec 15, 2023

Conversation

hendurhance
Copy link
Contributor

Description:

Issue: #42

Fix Commit: [feat-valid-vouchers 1f2ea43]

I've created a pull request to address the issue raised by @Temian1 regarding checking the validity of a voucher. The proposed change introduces a new function called isValid() that allows users to check whether a voucher is still valid or has been used.

Code Changes:

/**
 * @param string $code
 * @return bool
 */
public function isValid(string $code): bool
{
    try {
        $this->check($code);
    } catch (VoucherIsInvalid $exception) {
        return false;
    } catch (VoucherExpired $exception) {
        return false;
    }

    return true;
}

This function will return true if the voucher is valid and false if it's invalid or has expired.

Copy link
Member

@mechelon mechelon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next to the code change, could you add a sentence to the README so the new feature is documented? Thanks!

Nice addition. 👍

src/Vouchers.php Outdated Show resolved Hide resolved
@hendurhance
Copy link
Contributor Author

Thank you for your feedback! I've made the requested changes, introducing two distinct methods, isValidCode and isValidVoucher, to enhance clarity and consistency. You can now easily validate voucher codes or voucher models without any ambiguity.

Additionally, I've updated the README to reflect these changes. Now, you can refer to the documentation for clear usage examples:

Vouchers::isValidCode('ABCD-EFGH'); // true or false
Vouchers::isValidVoucher($voucher); // true or false

@mechelon mechelon merged commit 3ed053e into beyondcode:master Dec 15, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants