From ec7ebfc6696951d1eeebdf051992c54b4074fecf Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Sun, 10 Dec 2023 15:33:34 +0100 Subject: [PATCH] Fix bug --- src/Rules/Postalcode.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Rules/Postalcode.php b/src/Rules/Postalcode.php index 76bdc13..397e3d2 100644 --- a/src/Rules/Postalcode.php +++ b/src/Rules/Postalcode.php @@ -19,7 +19,7 @@ class Postalcode extends AbstractRule implements DataAwareRule * * @var array */ - protected $data; + protected $data = []; /** * Create a new rule instance with allowed countrycodes @@ -78,18 +78,6 @@ public function isValid(mixed $value): bool return false; } - protected function getCountryCodes(): array - { - if (count($this->countrycodes) == 0) { - // return country code by reference - if (is_array($this->data) && array_key_exists($this->reference, $this->data)) { - return $this->data[$this->reference]; - } - } - - return $this->countrycodes; - } - /** * Return regex patterns for allowed country codes * @@ -107,6 +95,18 @@ protected function getPatterns(): array }); } + protected function getCountryCodes(): array + { + if (count($this->countrycodes) == 0) { + // return country code by reference + if (is_array($this->data) && array_key_exists($this->reference, $this->data)) { + return [$this->data[$this->reference]]; + } + } + + return $this->countrycodes; + } + /** * Return regex pattern for postal code of current country code *