From 6b1fb19e1ce22c0cfdca2cb1a13f19c4e3bfc0dd Mon Sep 17 00:00:00 2001 From: berliner Date: Fri, 29 Nov 2024 17:06:54 +0100 Subject: [PATCH] HPC-9940: Prevent errors by not trying to do math on strings --- .../ghi_plans/src/ApiObjects/Mocks/PlanOverviewPlanMock.php | 2 +- .../ghi_plans/src/ApiObjects/Partials/PlanOverviewPlan.php | 6 +++--- html/modules/custom/hpc_common/src/Helpers/CommonHelper.php | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/html/modules/custom/ghi_plans/src/ApiObjects/Mocks/PlanOverviewPlanMock.php b/html/modules/custom/ghi_plans/src/ApiObjects/Mocks/PlanOverviewPlanMock.php index 461b2e2f9..da5a361f0 100644 --- a/html/modules/custom/ghi_plans/src/ApiObjects/Mocks/PlanOverviewPlanMock.php +++ b/html/modules/custom/ghi_plans/src/ApiObjects/Mocks/PlanOverviewPlanMock.php @@ -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; } /** diff --git a/html/modules/custom/ghi_plans/src/ApiObjects/Partials/PlanOverviewPlan.php b/html/modules/custom/ghi_plans/src/ApiObjects/Partials/PlanOverviewPlan.php index d7fbfe309..8cd2f79a7 100644 --- a/html/modules/custom/ghi_plans/src/ApiObjects/Partials/PlanOverviewPlan.php +++ b/html/modules/custom/ghi_plans/src/ApiObjects/Partials/PlanOverviewPlan.php @@ -239,7 +239,7 @@ public function isPartOfGho() { * The plan funding. */ public function getFunding() { - return $this->funding; + return (int) $this->funding; } /** @@ -249,7 +249,7 @@ public function getFunding() { * The coverage for a plan. */ public function getCoverage() { - return $this->coverage; + return (float) $this->coverage; } /** @@ -259,7 +259,7 @@ public function getCoverage() { * The plan funding. */ public function getRequirements() { - return $this->requirements; + return (int) $this->requirements; } /** diff --git a/html/modules/custom/hpc_common/src/Helpers/CommonHelper.php b/html/modules/custom/hpc_common/src/Helpers/CommonHelper.php index 50b1a6199..4857f8259 100644 --- a/html/modules/custom/hpc_common/src/Helpers/CommonHelper.php +++ b/html/modules/custom/hpc_common/src/Helpers/CommonHelper.php @@ -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); }