Skip to content

Commit

Permalink
Merge pull request #1235 from UN-OCHA/release-versions/v1.13.4
Browse files Browse the repository at this point in the history
HPC-9940: Prevent errors by not trying to do math on strings
  • Loading branch information
berliner authored Nov 29, 2024
2 parents a13ff46 + cbc5ba4 commit 0e069fd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function getCaseloadValue($metric_type, $metric_name = NULL, $fallback_ty
if (!array_key_exists($metric_type, $map)) {
return NULL;
}
return $raw_data->{$map[$metric_type]} ?? NULL;
return (int) $raw_data->{$map[$metric_type]} ?? NULL;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function isPartOfGho() {
* The plan funding.
*/
public function getFunding() {
return $this->funding;
return (int) $this->funding;
}

/**
Expand All @@ -249,7 +249,7 @@ public function getFunding() {
* The coverage for a plan.
*/
public function getCoverage() {
return $this->coverage;
return (float) $this->coverage;
}

/**
Expand All @@ -259,7 +259,7 @@ public function getCoverage() {
* The plan funding.
*/
public function getRequirements() {
return $this->requirements;
return (int) $this->requirements;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions html/modules/custom/hpc_common/src/Helpers/CommonHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CommonHelper {
* Round the value to 3 decimal places by default.
*/
public static function calculateRatio($value1, $value2, $round = 3) {
$value1 = is_string($value1) ? (float) $value1 : $value1;
$value2 = is_string($value2) ? (float) $value2 : $value2;
$ratio = !empty($value2) ? $value1 / $value2 : 0;
return round($ratio, $round);
}
Expand Down

0 comments on commit 0e069fd

Please sign in to comment.