Ine null date

This commit is contained in:
Juan Pablo Vial
2025-05-05 18:14:20 -04:00
parent ea8f483dd5
commit af68c4b8ec

View File

@ -5,8 +5,8 @@ use Exception;
use DateTimeInterface; use DateTimeInterface;
use DateTimeImmutable; use DateTimeImmutable;
use DateInterval; use DateInterval;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Client\ClientInterface; use Psr\Http\Client\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use Incoviba\Common\Implement\Exception\EmptyResponse; use Incoviba\Common\Implement\Exception\EmptyResponse;
use Incoviba\Common\Define\Money\Provider; use Incoviba\Common\Define\Money\Provider;
@ -19,8 +19,11 @@ class Ine implements Provider
* @throws EmptyResponse * @throws EmptyResponse
* @throws Exception * @throws Exception
*/ */
public function get(string $money_symbol, DateTimeInterface $dateTime): float public function get(string $money_symbol, ?DateTimeInterface $dateTime = null): float
{ {
if ($dateTime === null) {
$dateTime = new DateTimeImmutable();
}
$end = new DateTimeImmutable($dateTime->format('Y-m-1')); $end = new DateTimeImmutable($dateTime->format('Y-m-1'));
$start = $end->sub(new DateInterval('P1M')); $start = $end->sub(new DateInterval('P1M'));
return $this->getVar($start, $end); return $this->getVar($start, $end);
@ -42,9 +45,6 @@ class Ine implements Provider
$request_uri = implode('?', [ $request_uri = implode('?', [
$this->uri, $this->uri,
http_build_query($request_query), http_build_query($request_query),
/*implode('&', array_map(function($val, $key) {
return "{$key}={$val}";
}, $request_query, array_keys($request_query)))*/
]); ]);
try { try {
$response = $this->client->get($request_uri); $response = $this->client->get($request_uri);