From 4560966002f0e2c1a98e16b6f0d23f76b90d09ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 5 Sep 2023 09:54:49 +0200 Subject: [PATCH] Fix: Add parameter type declarations (#724) --- roave-bc-check.yaml | 18 ++++++++++++++++++ src/Faker/Calculator/Ean.php | 6 ++---- src/Faker/Calculator/Iban.php | 14 ++++---------- src/Faker/Calculator/Luhn.php | 16 ++++------------ 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/roave-bc-check.yaml b/roave-bc-check.yaml index 610c9e4e2f..9eb42b0e5b 100644 --- a/roave-bc-check.yaml +++ b/roave-bc-check.yaml @@ -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#' diff --git a/src/Faker/Calculator/Ean.php b/src/Faker/Calculator/Ean.php index 9c3daf1757..fbf11fcdad 100644 --- a/src/Faker/Calculator/Ean.php +++ b/src/Faker/Calculator/Ean.php @@ -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; @@ -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; diff --git a/src/Faker/Calculator/Iban.php b/src/Faker/Calculator/Iban.php index b00b18f010..19068fd775 100644 --- a/src/Faker/Calculator/Iban.php +++ b/src/Faker/Calculator/Iban.php @@ -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'; @@ -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; } @@ -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]; @@ -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); } diff --git a/src/Faker/Calculator/Luhn.php b/src/Faker/Calculator/Luhn.php index 0327668e53..4c1e6f5054 100644 --- a/src/Faker/Calculator/Luhn.php +++ b/src/Faker/Calculator/Luhn.php @@ -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); @@ -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'); @@ -53,11 +49,9 @@ 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; } @@ -65,11 +59,9 @@ public static function isValid($number) /** * 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.');