Skip to content

Commit

Permalink
Fix a type declaration problem on 32-bit environments
Browse files Browse the repository at this point in the history
In 32-bit environments, the UINT32_MAX cannot be represented by an
integer but it will become a floating point value, instead. Hence, we
need to allow parameters and return values of Util::limit to be of type
`float`.
  • Loading branch information
paulijar committed Oct 1, 2023
1 parent 5fdc64f commit 83669cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 15 additions & 3 deletions lib/Utility/Scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,11 @@ private function userL10N(string $userId) : IL10N {
return $this->l10nFactory->get('music', $languageCode);
}

private static function normalizeOrdinal(/*mixed*/ $ordinal) : ?int {
/**
* @param int|float|string|null $ordinal
* @return int|float|null
*/
private static function normalizeOrdinal(/*mixed*/ $ordinal) {
if (\is_string($ordinal)) {
// convert format '1/10' to '1'
$ordinal = \explode('/', $ordinal)[0];
Expand Down Expand Up @@ -710,7 +714,11 @@ private static function parseFileName(string $fileName) : array {
}
}

private static function normalizeYear(/*mixed*/ $date) : ?int {
/**
* @param int|float|string|null $date
* @return int|float|null
*/
private static function normalizeYear(/*mixed*/ $date) {
$year = null;
$matches = null;

Expand All @@ -725,7 +733,11 @@ private static function normalizeYear(/*mixed*/ $date) : ?int {
return Util::limit($year, Util::SINT32_MIN, Util::SINT32_MAX);
}

private static function normalizeUnsigned(/*mixed*/ $value) : ?int {
/**
* @param int|float|string|null $value
* @return int|float|null
*/
private static function normalizeUnsigned(/*mixed*/ $value) {
if (\is_numeric($value)) {
$value = (int)\round((float)$value);
} else {
Expand Down
6 changes: 5 additions & 1 deletion lib/Utility/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,12 @@ public static function swap(&$a, &$b) : void {
/**
* Limit an integer value between the specified minimum and maximum.
* A null value is a valid input and will produce a null output.
* @param int|float|null $input
* @param int|float $min
* @param int|float $max
* @return int|float|null
*/
public static function limit(?int $input, int $min, int $max) : ?int {
public static function limit($input, $min, $max) {
if ($input === null) {
return null;
} else {
Expand Down

0 comments on commit 83669cc

Please sign in to comment.