From 6955d2db9b0c7e0a158dcb6abaca27946affdd18 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Sun, 29 Dec 2024 12:20:46 -0600 Subject: [PATCH] Check if column value is a null type when decoding historical data (#58) Also check if column value is a null type In addition to checking if the column value is a string of 'null', also check if the column value is actually`null`. --- src/ResultDecoder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ResultDecoder.php b/src/ResultDecoder.php index 35f9bb0..1e15eed 100644 --- a/src/ResultDecoder.php +++ b/src/ResultDecoder.php @@ -228,13 +228,13 @@ private function createHistoricalData(array $json, int $index): HistoricalData foreach (['open', 'high', 'low', 'close', 'volume'] as $column) { $columnValue = $json['indicators']['quote'][0][$column][$index]; - if (!is_numeric($columnValue) && 'null' !== $columnValue) { + if (!is_numeric($columnValue) && 'null' !== $columnValue && !\is_null($columnValue)) { throw new ApiException(\sprintf('Not a number in column "%s": %s', $column, $column), ApiException::INVALID_VALUE); } } $columnValue = $json['indicators']['adjclose'][0]['adjclose'][$index]; - if (!is_numeric($columnValue) && 'null' !== $columnValue) { + if (!is_numeric($columnValue) && 'null' !== $columnValue && !\is_null($columnValue)) { throw new ApiException(\sprintf('Not a number in column "%s": %s', 'adjclose', 'adjclose'), ApiException::INVALID_VALUE); }