Skip to content

Commit

Permalink
Fix Coding Standards Issues #3
Browse files Browse the repository at this point in the history
  • Loading branch information
jrodriguesd committed Oct 14, 2024
1 parent a7a790c commit 24ba901
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
24 changes: 12 additions & 12 deletions src/ResultDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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'];
Expand All @@ -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'];
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ValueMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 24ba901

Please sign in to comment.