Skip to content

Commit

Permalink
Fix: Avoid using deprecated callable declaration (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 8, 2022
1 parent 8b91d43 commit ffcf9b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 22 deletions.
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,6 @@ parameters:
count: 1
path: src/Faker/Calculator/Iban.php

-
message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array\\<int\\|string, string\\>\\)\\: string, array\\{'self', 'alphaToNumberCallba…'\\} given\\.$#"
count: 1
path: src/Faker/Calculator/Iban.php

-
message: "#^Static method Faker\\\\Calculator\\\\Iban\\:\\:alphaToNumberCallback\\(\\) is unused\\.$#"
count: 1
path: src/Faker/Calculator/Iban.php

-
message: "#^Binary operation \"\\*\" between int and string results in an error\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
verbose="true"
>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=605"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=404"/>
</php>
<testsuites>
<testsuite name="Faker Test Suite">
Expand Down
18 changes: 7 additions & 11 deletions src/Faker/Calculator/Iban.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,20 @@ public static function checksum($iban)
$checkString = substr($iban, 4) . substr($iban, 0, 2) . '00';

// Replace all letters with their number equivalents
$checkString = preg_replace_callback('/[A-Z]/', ['self', 'alphaToNumberCallback'], $checkString);
$checkString = preg_replace_callback(
'/[A-Z]/',
static function (array $matches): string {
return (string) self::alphaToNumber($matches[0]);
},
$checkString,
);

// Perform mod 97 and subtract from 98
$checksum = 98 - self::mod97($checkString);

return str_pad($checksum, 2, '0', STR_PAD_LEFT);
}

/**
* @param string $match
*
* @return int
*/
private static function alphaToNumberCallback($match)
{
return self::alphaToNumber($match[0]);
}

/**
* Converts letter to number
*
Expand Down

0 comments on commit ffcf9b7

Please sign in to comment.