-
-
Notifications
You must be signed in to change notification settings - Fork 210
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
Auto multi validation #335
base: 3.x
Are you sure you want to change the base?
Conversation
Thanks to this, I can now easily handle all the information and save it in the database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey. Thanks for your patience. Leaving you here some comments.
* @param string $emailAddress | ||
* @return array | ||
*/ | ||
public static function create(string $emailAddress): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which are the reasons behing making it static? It prevents being injected as dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you are returning the lists of results, not a validator ready for use. I'd suggest to change the name to something like validationsResults
or similar.
$validator = new EmailValidator(); | ||
$result = []; | ||
|
||
foreach (self::$defaultValidators as $key => $val) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could just use ´MultipleValidationWithAnd´ at construction time. And remove line 15.
class EmailValidatorFactory | ||
{ | ||
/** @var [] */ | ||
protected static array $defaultValidators = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you expecting or encouraging extension? This prevents it. There is also no entry point to add additional/other validators than this.
You can do it via constructor arguments with sensible defaults (is like your idea here, but with simple extension point)
$result[get_class(new $val)] = $validator->isValid($emailAddress, new $val); | ||
} | ||
|
||
return $result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the validator's Result
type not useful? Maybe adding which validation is giving which result would be useful?
I created this branch to have every validation in one place by class name.
Example use: