-
-
Notifications
You must be signed in to change notification settings - Fork 212
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Egulias\EmailValidator; | ||
|
||
use Egulias\EmailValidator\EmailValidator; | ||
use Egulias\EmailValidator\Validation\DNSCheckValidation; | ||
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation; | ||
use Egulias\EmailValidator\Validation\RFCValidation; | ||
|
||
class EmailValidatorFactory | ||
{ | ||
/** @var [] */ | ||
protected static array $defaultValidators = [ | ||
RFCValidation::class, | ||
NoRFCWarningsValidation::class, | ||
DNSCheckValidation::class | ||
]; | ||
|
||
/** | ||
* @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 commentThe 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 commentThe 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 |
||
{ | ||
$validator = new EmailValidator(); | ||
$result = []; | ||
|
||
foreach (self::$defaultValidators as $key => $val) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could just use ´MultipleValidationWithAnd´ at construction time. And remove line 15. |
||
$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 commentThe reason will be displayed to describe this comment to others. Learn more. Is the validator's |
||
} | ||
} |
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)