Skip to content

Commit

Permalink
gdpr safe fake mobile and line line numbers
Browse files Browse the repository at this point in the history
+ laravel lint cleanup
  • Loading branch information
tanthammar committed Dec 6, 2023
1 parent f3b7a9d commit 713aab7
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 44 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/Factories/FakeMobileNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/
*/
Expand Down Expand Up @@ -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);
}
}
13 changes: 13 additions & 0 deletions src/Factories/FakePhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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),
]);
}
}
2 changes: 1 addition & 1 deletion src/Helpers/BusinessTypeFromNr.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelRulesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 2 additions & 10 deletions src/RuleHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
class RuleHelpers
{
/**
* @param string $vatID
* @return string
*
* @deprecated use BusinessNameFromVatID::lookup(string $vatID)
*/
public static function getBusinessNameFromVatID(string $vatID): string
Expand All @@ -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
Expand All @@ -39,6 +33,7 @@ public static function getVATDetailsFromVatID(string $vatID): object
'name' => '',
'address' => '',
]);

try {
return VatCalculator::getVATDetails($vatID) ?? $empty;
} catch (\Exception) {
Expand All @@ -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)) {
Expand Down
4 changes: 1 addition & 3 deletions src/Rules/BankGiro.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -30,8 +30,6 @@ public function passes($attribute, $value): bool

/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
Expand Down
4 changes: 1 addition & 3 deletions src/Rules/BankKonto.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -29,8 +29,6 @@ public function passes($attribute, $value): bool

/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/FixedLineNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions src/Rules/Latitude.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public function passes($attribute, $value): bool

/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
Expand Down
2 changes: 0 additions & 2 deletions src/Rules/Longitude.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public function passes($attribute, $value): bool

/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/MobileNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 0 additions & 3 deletions src/Rules/OrgNummer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class OrgNummer implements Rule
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value): bool
{
Expand All @@ -27,8 +26,6 @@ public function passes($attribute, $value): bool

/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
Expand Down
4 changes: 1 addition & 3 deletions src/Rules/PersonNummer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -29,8 +29,6 @@ public function passes($attribute, $value): bool

/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
Expand Down
3 changes: 0 additions & 3 deletions src/Rules/PersonOrOrgNummer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class PersonOrOrgNummer implements Rule
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value): bool
{
Expand All @@ -20,8 +19,6 @@ public function passes($attribute, $value): bool

/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions src/Rules/PlusGiro.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -30,8 +30,6 @@ public function passes($attribute, $value): bool

/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
Expand Down
4 changes: 1 addition & 3 deletions src/Rules/VatNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -33,8 +33,6 @@ public function passes($attribute, $value): bool

/**
* Get the validation error message.
*
* @return string
*/
public function message(): string
{
Expand Down

0 comments on commit 713aab7

Please sign in to comment.