From 38a26d185f948322971c3600dd1d84356f3f6b9e Mon Sep 17 00:00:00 2001 From: Arkadiusz Kondas Date: Tue, 6 Dec 2016 08:59:34 +0100 Subject: [PATCH] Secure index access and type safe comparision in statistic median --- src/Phpml/Math/Statistic/Mean.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Phpml/Math/Statistic/Mean.php b/src/Phpml/Math/Statistic/Mean.php index 07c43fe..581a122 100644 --- a/src/Phpml/Math/Statistic/Mean.php +++ b/src/Phpml/Math/Statistic/Mean.php @@ -34,11 +34,11 @@ class Mean self::checkArrayLength($numbers); $count = count($numbers); - $middleIndex = floor($count / 2); + $middleIndex = (int)floor($count / 2); sort($numbers, SORT_NUMERIC); $median = $numbers[$middleIndex]; - if (0 == $count % 2) { + if (0 === $count % 2) { $median = ($median + $numbers[$middleIndex - 1]) / 2; }