[Validator, FrameworkBundle] Add prevent DNS lookup option to EmailValidator#18142
[Validator, FrameworkBundle] Add prevent DNS lookup option to EmailValidator#18142patrick-mcdougle wants to merge 3 commits into
Conversation
patrick-mcdougle
commented
Mar 12, 2016
| Q | A |
|---|---|
| Branch | master |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | #16819 |
| License | MIT |
| Doc PR | symfony/symfony-docs#6359 |
|
Hi, @patrick-mcdougle. |
|
@AAstakhov I wanted to add some tests, but it looks like none of the |
|
Status: Reviewed Code is nice, tests pass. I tested it with different scenarios. @patrick-mcdougle, you are right, if checkMX and checkHost options are not tested than it does not make any sense in additional tests. |
|
Appveyor test failure likely unrelated. @symfony/deciders |
| @@ -81,7 +87,7 @@ public function validate($value, Constraint $constraint) | |||
| $host = substr($value, strpos($value, '@') + 1); | |||
|
|
|||
| // Check for host DNS resource records | |||
There was a problem hiding this comment.
This could be a little more DRY if there were just a single if (!$this->preventDNSLookups) conditional wrapping both the MX section and the hostname section. It would also keep the original if statements uncluttered by this new logic.
There was a problem hiding this comment.
Great suggestion! I'll make this change when I get back to my computer.
|
@patrick-mcdougle thanks for this contribution! My only concern is that variables with a "negation name" usually reduce code readability (especially when you negate them in a condition): if (!$this->preventDNSLookups && $constraint->checkMX) {
// ...
}Maybe we could use the same name used by PHP and rename this variable to if ($this->checkDnsRecord && $constraint->checkMX) {
// ...
} |
|
👎 Why not just mock |
|
@inso I'm pretty new at this and I'm just implementing this feature because there was an open issue about it. Can you further elaborate on your suggestion to mock in #16819? Perhaps this doesn't need to be a feature at all. I don't personally know how to do what you're proposing, but if you provided more insight on how that would work It'd be appreciated (perhaps open a PR testing In the meantime, I'm going to address Javier and Nate's comments. |
|
Alternatively, we could demote the |
|
PR updated. I'd suggest viewing with ?w=1 because the diff is misleading. |
| </service> | ||
|
|
||
| <service id="validator.email" class="Symfony\Component\Validator\Constraints\EmailValidator"> | ||
| <argument></argument> |
There was a problem hiding this comment.
Would be good IMO to add comment that those two options are passed in extension.
There was a problem hiding this comment.
The way we do this elsewhere is like this: <argument /> <!-- XXX -->
There was a problem hiding this comment.
Thanks, will do later tonight.
|
@patrick-mcdougle here you can review how time related functions are mocked |
|
@inso interesting. That probably is the right way to do this. I'll try that out later tonight. |
|
checkdnsrr mocking implemented in #18181 |
|
@nicolas-grekas do you think you could briefly explain how to use this in #16819? Once explained there, that issue can also be closed. Thanks. Also, nice palindromic PR number 😺 |