From f8980d8190cda4a05bca5d721fa6cc5b2f1dd19c 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 da09da3..32b65b5 100644 --- a/src/ResultDecoder.php +++ b/src/ResultDecoder.php @@ -250,13 +250,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); }