Skip to content

Commit

Permalink
Fix: Add parameter type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Sep 4, 2023
1 parent 1f83b68 commit 736e319
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
6 changes: 2 additions & 4 deletions src/Faker/Calculator/Ean.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ class Ean
*
* @see https://en.wikipedia.org/wiki/International_Article_Number
*
* @param string $digits
*
* @return int
*/
public static function checksum($digits)
public static function checksum(string $digits)
{
$sequence = (strlen($digits) + 1) === 8 ? [3, 1] : [1, 3];
$sums = 0;
Expand All @@ -41,7 +39,7 @@ public static function checksum($digits)
*
* @return bool
*/
public static function isValid($ean)
public static function isValid(string $ean)
{
if (!preg_match(self::PATTERN, $ean)) {
return false;
Expand Down
14 changes: 4 additions & 10 deletions src/Faker/Calculator/Iban.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ class Iban
/**
* Generates IBAN Checksum
*
* @param string $iban
*
* @return string Checksum (numeric string)
*/
public static function checksum($iban)
public static function checksum(string $iban)
{
// Move first four digits to end and set checksum to '00'
$checkString = substr($iban, 4) . substr($iban, 0, 2) . '00';
Expand All @@ -34,11 +32,9 @@ static function (array $matches): string {
/**
* Converts letter to number
*
* @param string $char
*
* @return int
*/
public static function alphaToNumber($char)
public static function alphaToNumber(string $char)
{
return ord($char) - 55;
}
Expand All @@ -50,7 +46,7 @@ public static function alphaToNumber($char)
*
* @return int
*/
public static function mod97($number)
public static function mod97(string $number)
{
$checksum = (int) $number[0];

Expand All @@ -64,11 +60,9 @@ public static function mod97($number)
/**
* Checks whether an IBAN has a valid checksum
*
* @param string $iban
*
* @return bool
*/
public static function isValid($iban)
public static function isValid(string $iban)
{
return self::checksum($iban) === substr($iban, 2, 2);
}
Expand Down
16 changes: 4 additions & 12 deletions src/Faker/Calculator/Luhn.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
class Luhn
{
/**
* @param string $number
*
* @return int
*/
private static function checksum($number)
private static function checksum(string $number)
{
$number = (string) $number;
$length = strlen($number);
Expand All @@ -35,11 +33,9 @@ private static function checksum($number)
}

/**
* @param string $partialNumber
*
* @return string
*/
public static function computeCheckDigit($partialNumber)
public static function computeCheckDigit(string $partialNumber)
{
$checkDigit = self::checksum($partialNumber . '0');

Expand All @@ -53,23 +49,19 @@ public static function computeCheckDigit($partialNumber)
/**
* Checks whether a number (partial number + check digit) is Luhn compliant
*
* @param string $number
*
* @return bool
*/
public static function isValid($number)
public static function isValid(string $number)
{
return self::checksum($number) === 0;
}

/**
* Generate a Luhn compliant number.
*
* @param string $partialValue
*
* @return string
*/
public static function generateLuhnNumber($partialValue)
public static function generateLuhnNumber(string $partialValue)
{
if (!preg_match('/^\d+$/', $partialValue)) {
throw new \InvalidArgumentException('Argument should be an integer.');
Expand Down

0 comments on commit 736e319

Please sign in to comment.