Skip to content

Commit

Permalink
Filter scheme expressions before testing VAT number (#4)
Browse files Browse the repository at this point in the history
* Small optimization, by limiting the amount of expressions tested for a given VAT number

* Removed unused debug variable

* applied coding standard
  • Loading branch information
proggeler authored and antalaron committed Jul 20, 2018
1 parent 3c65d8e commit 79d385e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/VatNumberValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ public function validate($value, Constraint $constraint)
return;
}

// Use only the expressions for the given country code
$schemes = preg_grep('/^\/\^\('.preg_quote(substr($value, 0, 2), '/').'/', $this->schemes);

// Check the string against the regular expressions for all types of
// VAT numbers
foreach ($this->schemes as $scheme) {
foreach ($schemes as $scheme) {
// Have we recognised the VAT number?
if (0 !== preg_match($scheme, $value, $match)) {
// Yes - we have:
Expand Down

0 comments on commit 79d385e

Please sign in to comment.