Example #1
0
 /**
  * {@inheritdoc}
  */
 public function validate($postcode, $countryId)
 {
     $postCodes = $this->postCodesConfig->getPostCodes();
     if (isset($postCodes[$countryId]) && is_array($postCodes[$countryId])) {
         $patterns = $postCodes[$countryId];
         foreach ($patterns as $pattern) {
             preg_match('/' . $pattern['pattern'] . '/', $postcode, $matches);
             if (count($matches)) {
                 return true;
             }
         }
         return false;
     }
     throw new \InvalidArgumentException('Provided countryId does not exist.');
 }