Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 374c96b42c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| return [ | ||
| 'valorConvertido' => $request->getAmount() * $request->getRate(), |
There was a problem hiding this comment.
Avoid binary float artifacts in monetary conversion
Using direct float multiplication for valorConvertido can produce visibly wrong monetary values for some decimal inputs (for example, 0.1 * 0.2 yields 0.020000000000000004 in PHP), which hurts API accuracy and can break strict client assertions. Since this endpoint returns currency amounts, the result should be normalized to a defined precision (or computed with decimal-safe arithmetic) before serializing the response.
Useful? React with 👍 / 👎.
Contexto
Implementa a API REST de conversão de moedas do desafio.
O que foi feito
src/index.phpExchangeRequestpara representar os dados validados da rotaExchangeRequestFactorypara validar e extrair/exchange/{amount}/{from}/{to}/{rate}ExchangeServicepara aplicar a regra de conversão e definir o símbolo da moedaJsonResponsepara centralizar a resposta JSONBadRequestExceptionpara tratar requisições inválidas com status 400Como validar
php -S localhost:8000 src/index.phphttp://localhost:8000/exchange/10/BRL/USD/4.50composer testcomposer lintEvidências
Validação manual
Testes automatizados
Lint