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 2aaf3f4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
18 changes: 18 additions & 0 deletions roave-bc-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,30 @@ parameters:
- '#\[BC\] CHANGED: Property Faker\\Provider\\[a-z_A-Z]+\\[a-zA-Z]+::\$[1-9a-zA-Z]+ changed default value#'
- '#\[BC\] CHANGED: Property Faker\\Provider\\[a-zA-Z]+::\$[1-9a-zA-Z]+ changed default value#'
- '#\[BC\] CHANGED: The number of required arguments for Faker\\Container\\ContainerBuilder\#add\(\) increased from 1 to 2#'
- '#\[BC\] CHANGED: The parameter \$char of Faker\\Calculator\\Iban::alphaToNumber\(\) changed from no type to a non-contravariant string#'
- '#\[BC\] CHANGED: The parameter \$char of Faker\\Calculator\\Iban::alphaToNumber\(\) changed from no type to string#'
- '#\[BC\] CHANGED: The parameter \$container of Faker\\Generator\#\_\_construct\(\) changed from Psr\\Container\\ContainerInterface\|null to a non-contravariant Faker\\Container\\ContainerInterface\|null#'
- '#\[BC\] CHANGED: The parameter \$container of Faker\\Generator\#\_\_construct\(\) changed from Psr\\Container\\ContainerInterface\|null to Faker\\Container\\ContainerInterface\|null#'
- '#\[BC\] CHANGED: The parameter \$digits of Faker\\Calculator\\Ean::checksum\(\) changed from no type to a non-contravariant string#'
- '#\[BC\] CHANGED: The parameter \$digits of Faker\\Calculator\\Ean::checksum\(\) changed from no type to string#'
- '#\[BC\] CHANGED: The parameter \$ean of Faker\\Calculator\\Ean::isValid\(\) changed from no type to a non-contravariant string#'
- '#\[BC\] CHANGED: The parameter \$ean of Faker\\Calculator\\Ean::isValid\(\) changed from no type to string#'
- '#\[BC\] CHANGED: The parameter \$generator of Faker\\UniqueGenerator\#\_\_construct\(\) changed from Faker\\Generator to no type#'
- '#\[BC\] CHANGED: The parameter \$generator of Faker\\ValidGenerator\#\_\_construct\(\) changed from Faker\\Generator to no type#'
- '#\[BC\] CHANGED: The parameter \$iban of Faker\\Calculator\\Iban::checksum\(\) changed from no type to a non-contravariant string#'
- '#\[BC\] CHANGED: The parameter \$iban of Faker\\Calculator\\Iban::checksum\(\) changed from no type to string#'
- '#\[BC\] CHANGED: The parameter \$iban of Faker\\Calculator\\Iban::isValid\(\) changed from no type to a non-contravariant string#'
- '#\[BC\] CHANGED: The parameter \$iban of Faker\\Calculator\\Iban::isValid\(\) changed from no type to string#'
- '#\[BC\] CHANGED: The parameter \$max of Faker\\Extension\\NumberExtension\#randomFloat\(\) changed from float to float\|null#'
- '#\[BC\] CHANGED: The parameter \$name of Faker\\Container\\ContainerBuilder\#add\(\) changed from string\|null to a non-contravariant string#'
- '#\[BC\] CHANGED: The parameter \$number of Faker\\Calculator\\Iban::mod97\(\) changed from no type to a non-contravariant string#'
- '#\[BC\] CHANGED: The parameter \$number of Faker\\Calculator\\Iban::mod97\(\) changed from no type to string#'
- '#\[BC\] CHANGED: The parameter \$number of Faker\\Calculator\\Luhn::isValid\(\) changed from no type to a non-contravariant string#'
- '#\[BC\] CHANGED: The parameter \$number of Faker\\Calculator\\Luhn::isValid\(\) changed from no type to string#'
- '#\[BC\] CHANGED: The parameter \$partialNumber of Faker\\Calculator\\Luhn::computeCheckDigit\(\) changed from no type to a non-contravariant string#'
- '#\[BC\] CHANGED: The parameter \$partialNumber of Faker\\Calculator\\Luhn::computeCheckDigit\(\) changed from no type to string#'
- '#\[BC\] CHANGED: The parameter \$partialValue of Faker\\Calculator\\Luhn::generateLuhnNumber\(\) changed from no type to a non-contravariant string#'
- '#\[BC\] CHANGED: The parameter \$partialValue of Faker\\Calculator\\Luhn::generateLuhnNumber\(\) changed from no type to string#'
- '#\[BC\] CHANGED: The parameter \$value of Faker\\Container\\ContainerBuilder\#add\(\) changed from no type to a non-contravariant string#'
- '#\[BC\] CHANGED: The return type of Faker\\Extension\\PersonExtension\#name\(\) changed from no type to string#'
- '#\[BC\] CHANGED: Type documentation for property Faker\\Provider\\en_ZA\\Internet::\$tld changed from having no type to array#'
Expand Down
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 2aaf3f4

Please sign in to comment.