diff --git a/src/ApiClient.php b/src/ApiClient.php index 9753503..6aba35a 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -261,7 +261,7 @@ private function validateIntervals(string $interval): void { $allowedIntervals = [self::INTERVAL_1_DAY, self::INTERVAL_1_WEEK, self::INTERVAL_1_MONTH]; if (!\in_array($interval, $allowedIntervals)) { - throw new \InvalidArgumentException(sprintf('Interval must be one of: %s', implode(', ', $allowedIntervals))); + throw new \InvalidArgumentException(\sprintf('Interval must be one of: %s', implode(', ', $allowedIntervals))); } } diff --git a/src/Exception/InvalidValueException.php b/src/Exception/InvalidValueException.php index c167298..49a2d6c 100644 --- a/src/Exception/InvalidValueException.php +++ b/src/Exception/InvalidValueException.php @@ -8,6 +8,6 @@ class InvalidValueException extends \Exception { public function __construct(string $type) { - parent::__construct(sprintf('Not a %s', $type)); + parent::__construct(\sprintf('Not a %s', $type)); } } diff --git a/src/ResultDecoder.php b/src/ResultDecoder.php index 65ca633..9a5a4bc 100644 --- a/src/ResultDecoder.php +++ b/src/ResultDecoder.php @@ -150,7 +150,7 @@ private function createSearchResultFromJson(array $json): SearchResult { $missingFields = array_diff(self::SEARCH_RESULT_FIELDS, array_keys($json)); if ($missingFields) { - throw new ApiException(sprintf('Search result is missing fields: %s', implode(', ', $missingFields)), ApiException::INVALID_RESPONSE); + throw new ApiException(\sprintf('Search result is missing fields: %s', implode(', ', $missingFields)), ApiException::INVALID_RESPONSE); } return new SearchResult( @@ -178,7 +178,7 @@ private function validateHeaderLines(string $responseBody, array $expectedHeader $headerLine = array_shift($lines); $expectedHeaderLine = implode(',', $expectedHeader); if ($headerLine !== $expectedHeaderLine) { - throw new ApiException(sprintf('CSV header line did not match expected header line, given: %s, expected: %s', $headerLine, $expectedHeaderLine), ApiException::INVALID_RESPONSE); + throw new ApiException(\sprintf('CSV header line did not match expected header line, given: %s, expected: %s', $headerLine, $expectedHeaderLine), ApiException::INVALID_RESPONSE); } return $lines; @@ -189,7 +189,7 @@ private function validateDate(string $value): \DateTime try { return new \DateTime($value, new \DateTimeZone('UTC')); } catch (\Exception $e) { - throw new ApiException(sprintf('Not a date in column "Date":%s', $value), ApiException::INVALID_VALUE); + throw new ApiException(\sprintf('Not a date in column "Date":%s', $value), ApiException::INVALID_VALUE); } } @@ -217,19 +217,19 @@ private function createHistoricalData(array $json, int $index): HistoricalData if ($dateStr) { $date = $this->validateDate($dateStr); } else { - throw new ApiException(sprintf('Not a date in column "Date":%s', $dateStr), ApiException::INVALID_VALUE); + throw new ApiException(\sprintf('Not a date in column "Date":%s', $json['timestamp'][$index]), ApiException::INVALID_VALUE); } foreach (['open', 'high', 'low', 'close', 'volume'] as $column) { $columnValue = $json['indicators']['quote'][0][$column][$index]; if (!is_numeric($columnValue) && 'null' !== $columnValue) { - throw new ApiException(sprintf('Not a number in column "%s": %s', $column, $column), ApiException::INVALID_VALUE); + 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) { - throw new ApiException(sprintf('Not a number in column "%s": %s', 'adjclose', 'adjclose'), ApiException::INVALID_VALUE); + throw new ApiException(\sprintf('Not a number in column "%s": %s', 'adjclose', 'adjclose'), ApiException::INVALID_VALUE); } $open = (float) $json['indicators']['quote'][0]['open'][$index]; @@ -260,7 +260,7 @@ private function createDividendData(array $json): DividendData if ($dateStr) { $date = $this->validateDate($dateStr); } else { - throw new ApiException(sprintf('Not a date in column "Date":%s', $dateStr), ApiException::INVALID_VALUE); + throw new ApiException(\sprintf('Not a date in column "Date":%s', $json['date']), ApiException::INVALID_VALUE); } $dividends = (float) $json['amount']; @@ -286,7 +286,7 @@ private function createSplitData(array $json): SplitData if ($dateStr) { $date = $this->validateDate($dateStr); } else { - throw new ApiException(sprintf('Not a date in column "Date":%s', $dateStr), ApiException::INVALID_VALUE); + throw new ApiException(\sprintf('Not a date in column "Date":%s', $json['date']), ApiException::INVALID_VALUE); } $stockSplits = (string) $json['splitRatio']; @@ -318,7 +318,7 @@ private function createQuote(array $json): Quote try { $mappedValues[$field] = $this->valueMapper->mapValue($value, $type); } catch (InvalidValueException $e) { - throw new ApiException(sprintf('Not a %s in field "%s": %s', $type, $field, $value), ApiException::INVALID_VALUE, $e); + throw new ApiException(\sprintf('Not a %s in field "%s": %s', $type, $field, $value), ApiException::INVALID_VALUE, $e); } } } @@ -378,7 +378,7 @@ private function createOptionChain(array $json): OptionChain $mappedValues[$field] = $this->valueMapper->mapValue($value, $type); } } catch (InvalidValueException $e) { - throw new ApiException(sprintf('%s in field "%s": %s', $e->getMessage(), $field, json_encode($value)), ApiException::INVALID_VALUE, $e); + throw new ApiException(\sprintf('%s in field "%s": %s', $e->getMessage(), $field, json_encode($value)), ApiException::INVALID_VALUE, $e); } } @@ -406,7 +406,7 @@ private function createOption(array $json): Option $mappedValues[$field] = $this->valueMapper->mapValue($value, $type); } } catch (InvalidValueException $e) { - throw new ApiException(sprintf('%s in field "%s": %s', $e->getMessage(), $field, json_encode($value)), ApiException::INVALID_VALUE, $e); + throw new ApiException(\sprintf('%s in field "%s": %s', $e->getMessage(), $field, json_encode($value)), ApiException::INVALID_VALUE, $e); } } @@ -423,7 +423,7 @@ private function createOptionContract(array $values): OptionContract try { $mappedValues[$property] = $this->valueMapper->mapValue($value, self::OPTION_CONTRACT_FIELDS_MAP[$property]); } catch (InvalidValueException $e) { - throw new ApiException(sprintf('%s in field "%s": %s', $e->getMessage(), $property, json_encode($value)), ApiException::INVALID_VALUE, $e); + throw new ApiException(\sprintf('%s in field "%s": %s', $e->getMessage(), $property, json_encode($value)), ApiException::INVALID_VALUE, $e); } } diff --git a/src/ValueMapper.php b/src/ValueMapper.php index 3b6db58..1bf1b29 100644 --- a/src/ValueMapper.php +++ b/src/ValueMapper.php @@ -52,7 +52,7 @@ public function mapValue($rawValue, string $type, ?string $subType = null) return $this->mapArray($rawValue, $subType); default: - throw new \InvalidArgumentException(sprintf('Invalid data type %s', $type)); + throw new \InvalidArgumentException(\sprintf('Invalid data type %s', $type)); } }