Fix PhpStan complaining about arithmetic operations between string and int

This commit is contained in:
Eric Lippmann 2024-10-22 13:51:28 +02:00
parent 853b6ceb84
commit 28261d8a7f
3 changed files with 11 additions and 28 deletions

View File

@ -35,19 +35,20 @@ class MemoryLimit
$val = trim($string);
if (preg_match('/^(\d+)([KMG])$/', $val, $m)) {
$val = $m[1];
$val = (int) $m[1];
switch ($m[2]) {
case 'G':
$val *= 1024;
// Intentional fall-through
// no break
case 'M':
$val *= 1024;
// Intentional fall-through
// no break
case 'K':
$val *= 1024;
}
}
return intval($val);
return (int) $val;
}
}

View File

@ -298,18 +298,20 @@ class IcingaConfigHelper
));
}
$duration = (int) $m[1];
switch ($m[2]) {
case 'd':
$value += $m[1] * 86400;
$value += $duration * 86400;
break;
case 'h':
$value += $m[1] * 3600;
$value += $duration * 3600;
break;
case 'm':
$value += $m[1] * 60;
$value += $duration * 60;
break;
default:
$value += (int) $m[1];
$value += $duration;
}
}

View File

@ -240,11 +240,6 @@ parameters:
count: 1
path: application/views/helpers/FormStoredPassword.php
-
message: "#^Binary operation \"\\*\\=\" between string and 1024 results in an error\\.$#"
count: 1
path: library/Director/Application/MemoryLimit.php
-
message: "#^Constructor of class Icinga\\\\Module\\\\Director\\\\Core\\\\RestApiClient has an unused parameter \\$cn\\.$#"
count: 1
@ -395,21 +390,6 @@ parameters:
count: 1
path: library/Director/IcingaConfig/AgentWizard.php
-
message: "#^Binary operation \"\\*\" between string and 3600 results in an error\\.$#"
count: 1
path: library/Director/IcingaConfig/IcingaConfigHelper.php
-
message: "#^Binary operation \"\\*\" between string and 60 results in an error\\.$#"
count: 1
path: library/Director/IcingaConfig/IcingaConfigHelper.php
-
message: "#^Binary operation \"\\*\" between string and 86400 results in an error\\.$#"
count: 1
path: library/Director/IcingaConfig/IcingaConfigHelper.php
-
message: "#^Call to an undefined method Icinga\\\\Module\\\\Director\\\\Web\\\\Form\\\\QuickForm\\:\\:getSentOrObjectSetting\\(\\)\\.$#"
count: 3