diff --git a/composer.json b/composer.json index a21a8df..dd6cb20 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ], "require": { "php": "^8.1|^8.2", - "brick/phonenumber": "^0.4.0", + "brick/phonenumber": "^0.6.0", "byrokrat/banking": "^2.2", "laravel/framework": "^9.0|^10.0", "personnummer/personnummer": "^3.0.4", diff --git a/src/Factories/FakeMobileNumber.php b/src/Factories/FakeMobileNumber.php index 0b66df5..8170390 100644 --- a/src/Factories/FakeMobileNumber.php +++ b/src/Factories/FakeMobileNumber.php @@ -5,6 +5,7 @@ /** * Swedish mobile number formats, while waiting for PR * + * @see https://fakerphp.github.io/locales/sv_SE/#fakerprovidersv_semobilenumber * @see https://github.com/FakerPHP/Faker/pull/491 * @see https://www.pts.se/sv/bransch/telefoni/nummer-och-adressering/telefoninummerplanen/telefonnummers-struktur/ */ @@ -38,4 +39,10 @@ public static function make(bool $international = true): string return self::numerify($val); } + + /* Publishable GDPR Safe Swedish mobile number series */ + public static function gdprSafe(): string + { + return '070-1740' . fake()->numberBetween(605, 699); + } } diff --git a/src/Factories/FakePhoneNumber.php b/src/Factories/FakePhoneNumber.php index bd48026..a7198d0 100644 --- a/src/Factories/FakePhoneNumber.php +++ b/src/Factories/FakePhoneNumber.php @@ -4,6 +4,8 @@ /** * Swedish phone number formats, both landline and mobile + * + * @see https://fakerphp.github.io/locales/sv_SE/#fakerprovidersv_sephonenumber */ class FakePhoneNumber extends \Faker\Provider\PhoneNumber { @@ -50,4 +52,15 @@ public static function make(bool $international = true): string return self::numerify($val); } + + /* Publishable GDPR Safe Swedish landline phone number series */ + public static function gdprSafe(): string + { + return fake()->randomElement([ + '031-3900' . fake()->numberBetween(600, 699), + '040-6280' . fake()->numberBetween(400, 499), + '08-46500' . fake()->numberBetween(400, 499), + '0980-319' . fake()->numberBetween(200, 299), + ]); + } } diff --git a/src/Helpers/BusinessTypeFromNr.php b/src/Helpers/BusinessTypeFromNr.php index 4dd2a2c..1c5e8a5 100644 --- a/src/Helpers/BusinessTypeFromNr.php +++ b/src/Helpers/BusinessTypeFromNr.php @@ -9,7 +9,7 @@ class BusinessTypeFromNr { /** returns 'business', 'individual' or 'undefined' */ - public static function make(string|int $nr): string + public static function make(string | int $nr): string { if (filled($nr)) { if ((new PersonNummer)->passes(null, $nr)) { diff --git a/src/LaravelRulesServiceProvider.php b/src/LaravelRulesServiceProvider.php index 4df5714..e8fd755 100644 --- a/src/LaravelRulesServiceProvider.php +++ b/src/LaravelRulesServiceProvider.php @@ -59,7 +59,7 @@ public function bootingPackage(): void public function bootTranslations() { $name = $this->package->name; - $langPath = resource_path('lang/'.'vendor/'.$name); + $langPath = resource_path('lang/' . 'vendor/' . $name); $this->publishes([ $this->package->basePath('/../resources/lang') => $langPath, diff --git a/src/RuleHelpers.php b/src/RuleHelpers.php index dcc3e79..7c9f008 100644 --- a/src/RuleHelpers.php +++ b/src/RuleHelpers.php @@ -9,9 +9,6 @@ class RuleHelpers { /** - * @param string $vatID - * @return string - * * @deprecated use BusinessNameFromVatID::lookup(string $vatID) */ public static function getBusinessNameFromVatID(string $vatID): string @@ -24,9 +21,6 @@ public static function getBusinessNameFromVatID(string $vatID): string } /** - * @param string $vatID - * @return object - * * @deprecated use VatDetailsFromVatID::lookup(string $vatID) */ public static function getVATDetailsFromVatID(string $vatID): object @@ -39,6 +33,7 @@ public static function getVATDetailsFromVatID(string $vatID): object 'name' => '', 'address' => '', ]); + try { return VatCalculator::getVATDetails($vatID) ?? $empty; } catch (\Exception) { @@ -47,12 +42,9 @@ public static function getVATDetailsFromVatID(string $vatID): object } /** - * @param string|int $nr - * @return string - * * @deprecated use BusinessTypeFromNr::make(string|int $nr) */ - public static function check_business_type(string|int $nr): string + public static function check_business_type(string | int $nr): string { if (filled($nr)) { if ((new PersonNummer)->passes(null, $nr)) { diff --git a/src/Rules/BankGiro.php b/src/Rules/BankGiro.php index 3a1b6b5..88f9cfb 100644 --- a/src/Rules/BankGiro.php +++ b/src/Rules/BankGiro.php @@ -14,13 +14,13 @@ class BankGiro implements Rule * * @param string $attribute * @param mixed $value - * @return bool */ public function passes($attribute, $value): bool { if (blank($value)) { return false; } + try { return (new BankgiroFactory)->createAccount($value)->getBankName() === BankNames::BANK_BANKGIRO; } catch (Exception $e) { @@ -30,8 +30,6 @@ public function passes($attribute, $value): bool /** * Get the validation error message. - * - * @return string */ public function message(): string { diff --git a/src/Rules/BankKonto.php b/src/Rules/BankKonto.php index 2e1b8f9..9cbaafc 100644 --- a/src/Rules/BankKonto.php +++ b/src/Rules/BankKonto.php @@ -13,13 +13,13 @@ class BankKonto implements Rule * * @param string $attribute * @param mixed $value - * @return bool */ public function passes($attribute, $value): bool { if (blank($value)) { return false; } + try { return filled((new AccountFactory)->createAccount($value)); } catch (Exception $e) { @@ -29,8 +29,6 @@ public function passes($attribute, $value): bool /** * Get the validation error message. - * - * @return string */ public function message(): string { diff --git a/src/Rules/FixedLineNumber.php b/src/Rules/FixedLineNumber.php index a97080d..46144ef 100644 --- a/src/Rules/FixedLineNumber.php +++ b/src/Rules/FixedLineNumber.php @@ -15,16 +15,16 @@ class FixedLineNumber implements Rule /** * @param string $attribute * @param mixed $value - * @return bool */ public function passes($attribute, $value): bool { if (blank($value)) { return false; } + try { if (! str_starts_with($value, '+')) { - $value = '+'.$value; + $value = '+' . $value; } $number = Validator::parse((string) $value); diff --git a/src/Rules/Latitude.php b/src/Rules/Latitude.php index 31ab222..238451b 100644 --- a/src/Rules/Latitude.php +++ b/src/Rules/Latitude.php @@ -20,8 +20,6 @@ public function passes($attribute, $value): bool /** * Get the validation error message. - * - * @return string */ public function message(): string { diff --git a/src/Rules/Longitude.php b/src/Rules/Longitude.php index 2fb19c7..5d2effd 100644 --- a/src/Rules/Longitude.php +++ b/src/Rules/Longitude.php @@ -20,8 +20,6 @@ public function passes($attribute, $value): bool /** * Get the validation error message. - * - * @return string */ public function message(): string { diff --git a/src/Rules/MobileNumber.php b/src/Rules/MobileNumber.php index 2890e56..d2e944b 100644 --- a/src/Rules/MobileNumber.php +++ b/src/Rules/MobileNumber.php @@ -15,16 +15,16 @@ class MobileNumber implements Rule /** * @param string $attribute * @param mixed $value - * @return bool */ public function passes($attribute, $value): bool { if (blank($value)) { return false; } + try { if (! str_starts_with($value, '+')) { - $value = '+'.$value; + $value = '+' . $value; } $number = Validator::parse((string) $value); diff --git a/src/Rules/OrgNummer.php b/src/Rules/OrgNummer.php index 921f27a..b97342a 100644 --- a/src/Rules/OrgNummer.php +++ b/src/Rules/OrgNummer.php @@ -14,7 +14,6 @@ class OrgNummer implements Rule * * @param string $attribute * @param mixed $value - * @return bool */ public function passes($attribute, $value): bool { @@ -27,8 +26,6 @@ public function passes($attribute, $value): bool /** * Get the validation error message. - * - * @return string */ public function message(): string { diff --git a/src/Rules/PersonNummer.php b/src/Rules/PersonNummer.php index 552e958..81441a3 100644 --- a/src/Rules/PersonNummer.php +++ b/src/Rules/PersonNummer.php @@ -13,13 +13,13 @@ class PersonNummer implements Rule * * @param string $attribute * @param mixed $value - * @return bool */ public function passes($attribute, $value): bool { if (blank($value)) { return false; } + try { return PersonNummerVerifier::valid(CleanNumber::make($value)); } catch (\Exception $e) { @@ -29,8 +29,6 @@ public function passes($attribute, $value): bool /** * Get the validation error message. - * - * @return string */ public function message(): string { diff --git a/src/Rules/PersonOrOrgNummer.php b/src/Rules/PersonOrOrgNummer.php index edb7196..5c0ca74 100644 --- a/src/Rules/PersonOrOrgNummer.php +++ b/src/Rules/PersonOrOrgNummer.php @@ -11,7 +11,6 @@ class PersonOrOrgNummer implements Rule * * @param string $attribute * @param mixed $value - * @return bool */ public function passes($attribute, $value): bool { @@ -20,8 +19,6 @@ public function passes($attribute, $value): bool /** * Get the validation error message. - * - * @return string */ public function message(): string { diff --git a/src/Rules/PhoneNumber.php b/src/Rules/PhoneNumber.php index 9ef38cd..f49b588 100644 --- a/src/Rules/PhoneNumber.php +++ b/src/Rules/PhoneNumber.php @@ -14,16 +14,16 @@ class PhoneNumber implements Rule /** * @param string $attribute * @param mixed $value - * @return bool */ public function passes($attribute, $value): bool { if (blank($value)) { return false; } + try { if (! str_starts_with($value, '+')) { - $value = '+'.$value; + $value = '+' . $value; } return Validator::parse((string) $value)->isValidNumber(); diff --git a/src/Rules/PlusGiro.php b/src/Rules/PlusGiro.php index e556159..5deb8a0 100644 --- a/src/Rules/PlusGiro.php +++ b/src/Rules/PlusGiro.php @@ -14,13 +14,13 @@ class PlusGiro implements Rule * * @param string $attribute * @param mixed $value - * @return bool */ public function passes($attribute, $value): bool { if (blank($value)) { return false; } + try { return (new PlusgiroFactory)->createAccount($value)->getBankName() === BankNames::BANK_PLUSGIRO; } catch (Exception $e) { @@ -30,8 +30,6 @@ public function passes($attribute, $value): bool /** * Get the validation error message. - * - * @return string */ public function message(): string { diff --git a/src/Rules/VatNumber.php b/src/Rules/VatNumber.php index 2671629..3d7852c 100644 --- a/src/Rules/VatNumber.php +++ b/src/Rules/VatNumber.php @@ -15,13 +15,13 @@ class VatNumber implements Rule * * @param string $attribute * @param mixed $value - * @return bool */ public function passes($attribute, $value): bool { if (blank($value)) { return false; } + try { return VatCalculator::isValidVATNumber($value); } catch (VATCheckUnavailableException) { @@ -33,8 +33,6 @@ public function passes($attribute, $value): bool /** * Get the validation error message. - * - * @return string */ public function message(): string {