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

Validation Rule Constants #436

Closed
SmolSoftBoi opened this issue Mar 9, 2017 · 1 comment
Closed

Validation Rule Constants #436

SmolSoftBoi opened this issue Mar 9, 2017 · 1 comment

Comments

@SmolSoftBoi
Copy link
Contributor

This might just be me being clumsy, but I've had a few instances of incorrectly setting validation rules (typos, etc…), what about having rule constant strings?

For example:

class Rules
{
    const REQUIRED = 'required';
    const IS_NATURAL_NO_ZERO = 'is_natural_no_zero';
}

$rules = [
    'id' => implode('|', [Rules::REQUIRED, RULES::IS_NATURAL_NO_ZERO])
];

Could even add a convenience method to the validation class:

class Validation
{
    public static function concatRules(string ...$rules): string
    {
        return implode('|', $rules);
    }
}

$rules = [
    'id' => Validation::concatRules([Rules::REQUIRED, Rules::IS_NATURAL_NO_ZERO])
];
@lonnieezell
Copy link
Member

I'm not convinced of this one, @EpicKris. The only benefit is that the IDE could do autocomplete. I'm afraid, though, that if we add this due to the error-prone word required (and yes, I misspell it too often myself), then we will have to start creating a lot of special case rules like this.

So, sorry, not this one.

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

No branches or pull requests

2 participants