MDL-76356 various: avoid implicit conversion to int

PHP before version 8.1 automatically converted to int if the function
parameter (or array key) is expected to be int. PHP 8.1 shows notice in
this case
This commit is contained in:
Marina Glancy 2022-11-17 15:49:48 +01:00 committed by Eloy Lafuente (stronk7)
parent 594a8c5ab7
commit b1c97381b4
12 changed files with 18 additions and 18 deletions

View File

@ -278,7 +278,7 @@ if (empty($parallelrun)) {
// Print combined run o/p from processes.
$exitcodes = print_combined_run_output($processes, $stoponfail);
// Time to finish run.
$time = round(microtime(true) - $time, 1);
$time = round(microtime(true) - $time, 0);
echo "Finished in " . gmdate("G\h i\m s\s", $time) . PHP_EOL . PHP_EOL;
ksort($exitcodes);

View File

@ -893,7 +893,7 @@ class behat_config_util {
&& (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST)) {
echo "Bucket weightings:\n";
foreach ($weights as $k => $weight) {
echo $k + 1 . ": " . str_repeat('*', 70 * $nbuckets * $weight / $totalweight) . PHP_EOL;
echo $k + 1 . ": " . str_repeat('*', (int)(70 * $nbuckets * $weight / $totalweight)) . PHP_EOL;
}
}

View File

@ -459,10 +459,8 @@ class address_manager {
*/
protected function pack_int($int) {
if (PHP_INT_SIZE === 8) {
$left = 0xffffffff00000000;
$right = 0x00000000ffffffff;
$l = ($int & $left) >>32;
$r = $int & $right;
$l = intdiv($int, pow(2, 32)); // 32-bit integer quotient.
$r = $int % pow(2, 32); // 32-bit integer remaining.
return pack('NN', $l, $r);
} else {

View File

@ -285,7 +285,8 @@ abstract class base {
}
if (isset($plugin->incompatible) && $plugin->incompatible !== null) {
if ((ctype_digit($plugin->incompatible) || is_int($plugin->incompatible)) && (int) $plugin->incompatible > 0) {
if (((is_string($plugin->incompatible) && ctype_digit($plugin->incompatible)) || is_int($plugin->incompatible))
&& (int) $plugin->incompatible > 0) {
$this->pluginincompatible = intval($plugin->incompatible);
} else {
throw new coding_exception('Incorrect syntax in plugin incompatible declaration in '."$this->name");

View File

@ -511,7 +511,7 @@ class redis extends handler {
// time. If it is too small we will poll too much and if it is
// too large we will waste time waiting for no reason. 100ms is
// the default starting point.
$delay = rand($this->lockretry, $this->lockretry * 1.1);
$delay = rand($this->lockretry, (int)($this->lockretry * 1.1));
} else {
// If we don't get a lock within 5 seconds then there must be a
// very long lived process holding the lock so throttle back to

View File

@ -216,8 +216,8 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil
$im3 = imagecreate(512, 512);
}
$cx = $image->width / 2;
$cy = $image->height / 2;
$cx = floor($image->width / 2);
$cy = floor($image->height / 2);
if ($image->width < $image->height) {
$half = floor($image->width / 2.0);

View File

@ -229,7 +229,7 @@ class custom_completion extends activity_custom_completion {
*/
protected static function get_completionattendance_value(stdClass $log): int {
$summary = json_decode($log->meta);
return empty($summary->data->duration) ? 0 : $summary->data->duration / 60;
return empty($summary->data->duration) ? 0 : (int)($summary->data->duration / 60);
}
/**

View File

@ -493,7 +493,7 @@ class attempt {
* @return int|null the scaled value
*/
public function get_scaled(): ?int {
return $this->record->scaled;
return is_null($this->record->scaled) ? $this->record->scaled : (int)$this->record->scaled;
}
/**

View File

@ -228,8 +228,9 @@ class calculator {
$this->sumofmarkvariance += $this->stats->for_slot($slot)->markvariance;
if ($this->stats->for_slot($slot)->covariancewithoverallmark >= 0) {
$sumofcovariancewithoverallmark += sqrt($this->stats->for_slot($slot)->covariancewithoverallmark);
$covariancewithoverallmark = $this->stats->for_slot($slot)->covariancewithoverallmark;
if (null !== $covariancewithoverallmark && $covariancewithoverallmark >= 0) {
$sumofcovariancewithoverallmark += sqrt($covariancewithoverallmark);
}
}
$this->progress->end_progress();

View File

@ -917,8 +917,8 @@ abstract class question_utils {
'converted to roman numerals.', $number);
}
return self::$thousands[$number / 1000 % 10] . self::$hundreds[$number / 100 % 10] .
self::$tens[$number / 10 % 10] . self::$units[$number % 10];
return self::$thousands[floor($number / 1000) % 10] . self::$hundreds[floor($number / 100) % 10] .
self::$tens[floor($number / 10) % 10] . self::$units[$number % 10];
}
/**

View File

@ -239,7 +239,7 @@ class qtype_multianswer_textfield_renderer extends qtype_multianswer_subq_render
foreach ($subq->answers as $ans) {
$size = max($size, core_text::strlen(trim($ans->answer)));
}
$size = min(60, round($size + rand(0, $size * 0.15)));
$size = min(60, round($size + rand(0, (int)($size * 0.15))));
// The rand bit is to make guessing harder.
$inputattributes = array(

View File

@ -307,7 +307,7 @@ abstract class engine {
if ($now - $lastprogress >= manager::DISPLAY_INDEXING_PROGRESS_EVERY) {
$lastprogress = $now;
// The first date format is the same used in cron_trace_time_and_memory().
$options['progress']->output(date('H:i:s', $now) . ': Done to ' . userdate(
$options['progress']->output(date('H:i:s', (int)$now) . ': Done to ' . userdate(
$lastindexeddoc, get_string('strftimedatetimeshort', 'langconfig')), 1);
}
}