From 79d385e1f2779e362eddf3940cca864e388beeeb Mon Sep 17 00:00:00 2001 From: Bas de Mes Date: Fri, 20 Jul 2018 09:52:17 +0200 Subject: [PATCH] Filter scheme expressions before testing VAT number (#4) * Small optimization, by limiting the amount of expressions tested for a given VAT number * Removed unused debug variable * applied coding standard --- src/VatNumberValidator.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/VatNumberValidator.php b/src/VatNumberValidator.php index 0699cf7..9f53720 100644 --- a/src/VatNumberValidator.php +++ b/src/VatNumberValidator.php @@ -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: