Conversation
2 new issues
|
cdc2604 to
2a858d0
Compare
| } | ||
|
|
||
| $response = $this->apiRequest('latest', [ | ||
| 'base' => $this->getBaseCurrency(), |
2a858d0 to
66b5ed5
Compare
| * | ||
| * @return array<string, BigDecimal|float|int|string> | ||
| */ | ||
| protected function responseRates(array $response, string $key, string $provider): array |
|
|
||
| $normalised = []; | ||
| foreach ($rates as $currency => $rate) { | ||
| if (!$rate instanceof BigDecimal && !is_float($rate) && !is_int($rate) && !is_string($rate)) { |
| throw new ApiException('CurrencyAPI response did not contain a converted value.'); | ||
| } | ||
|
|
||
| $rate = BigDecimal::of((string) $converted) |
| } | ||
|
|
||
| $rate = BigDecimal::of((string) $converted) | ||
| ->dividedBy(BigDecimal::of((string) $this->amount), ConversionResult::DEFAULT_SCALE, RoundingMode::HALF_UP); |
| * | ||
| * @return array<string, BigDecimal|float|int|string> | ||
| */ | ||
| private function ratesFromData(mixed $data): array |
| use PHPUnit\Framework\Attributes\Test; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class CurrencyTest extends TestCase |
|
|
||
| class CurrencyTest extends TestCase | ||
| { | ||
| #[Test] |
| #[Test] | ||
| public function exposes_all_supported_currency_cases(): void | ||
| { | ||
| $this->assertCount(167, Currency::cases()); |
| $this->assertCount(167, Currency::cases()); | ||
| } | ||
|
|
||
| #[Test] |
| #[Test] | ||
| public function backed_value_matches_iso_code(): void | ||
| { | ||
| $this->assertSame('USD', Currency::USD->value); |
66b5ed5 to
7c25f37
Compare
| * | ||
| * @return array<string, BigDecimal|float|int|string> | ||
| */ | ||
| protected function responseRates(array $response, string $key, string $provider): array |
|
|
||
| $normalised = []; | ||
| foreach ($rates as $currency => $rate) { | ||
| if (!$rate instanceof BigDecimal && !is_float($rate) && !is_int($rate) && !is_string($rate)) { |
| throw new ApiException('CurrencyAPI response did not contain a converted value.'); | ||
| } | ||
|
|
||
| $rate = BigDecimal::of((string) $converted) |
| } | ||
|
|
||
| $rate = BigDecimal::of((string) $converted) | ||
| ->dividedBy(BigDecimal::of((string) $this->amount), ConversionResult::DEFAULT_SCALE, RoundingMode::HALF_UP); |
| * | ||
| * @return array<string, BigDecimal|float|int|string> | ||
| */ | ||
| private function ratesFromData(mixed $data): array |
| use PHPUnit\Framework\Attributes\Test; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class CurrencyTest extends TestCase |
|
|
||
| class CurrencyTest extends TestCase | ||
| { | ||
| #[Test] |
| #[Test] | ||
| public function exposes_all_supported_currency_cases(): void | ||
| { | ||
| $this->assertCount(167, Currency::cases()); |
| $this->assertCount(167, Currency::cases()); | ||
| } | ||
|
|
||
| #[Test] |
| #[Test] | ||
| public function backed_value_matches_iso_code(): void | ||
| { | ||
| $this->assertSame('USD', Currency::USD->value); |
- Add open graph preview image in PNG and SVG formats. - Create `resources/README.md` to document resource folder contents. - Remove obsolete PSD file.
- Update README to reflect new API wrapper description and upgrade notes. - Add UPGRADING.md file with detailed upgrade instructions from 1.x to 2.x.
- Update CI workflow to trigger on `main` branch only. - Change push instructions in CONTRIBUTING.md to use `main` branch. - Update README badges to reflect `main` branch for CI and coverage.
- Update GitHub Actions workflow to include linting jobs. - Modify dependabot configuration for improved dependency updates. - Add linting configuration files for Markdown and YAML.
| with: | ||
| persist-credentials: false | ||
| - name: Markdown Lint | ||
| uses: DavidAnson/markdownlint-cli2-action@v23 |
| config: ".markdownlint.yaml" | ||
|
|
||
| - name: YAML Lint | ||
| uses: karancode/yamllint-github-action@master |
| * | ||
| * @return array<string, BigDecimal|float|int|string> | ||
| */ | ||
| protected function responseRates(array $response, string $key, string $provider): array |
|
|
||
| $normalised = []; | ||
| foreach ($rates as $currency => $rate) { | ||
| if (!$rate instanceof BigDecimal && !is_float($rate) && !is_int($rate) && !is_string($rate)) { |
| throw new ApiException('CurrencyAPI response did not contain a converted value.'); | ||
| } | ||
|
|
||
| $rate = BigDecimal::of((string) $converted) |
| /** | ||
| * @throws MathException | ||
| */ | ||
| private function toBigDecimal(BigDecimal|float|int|string $value): BigDecimal |
There was a problem hiding this comment.
Found 3 issues:
1. Method Otherguy\Currency\Results\ConversionResult::toBigDecimal() has invalid return type Brick\Math\BigDecimal. [phpstan:class.notFound]
2. PHPDoc tag @throws with type Brick\Math\Exception\MathException is not subtype of Throwable [phpstan:throws.notThrowable]
3. Parameter $value of method Otherguy\Currency\Results\ConversionResult::toBigDecimal() has invalid type Brick\Math\BigDecimal. [phpstan:class.notFound]
| */ | ||
| private function toBigDecimal(BigDecimal|float|int|string $value): BigDecimal | ||
| { | ||
| return $value instanceof BigDecimal ? $value : BigDecimal::of($value); |
| use PHPUnit\Framework\Attributes\Test; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class CurrencyTest extends TestCase |
|
|
||
| class CurrencyTest extends TestCase | ||
| { | ||
| #[Test] |
| #[Test] | ||
| public function exposes_all_supported_currency_cases(): void | ||
| { | ||
| $this->assertCount(167, Currency::cases()); |
…rivers - Add triage rules to Qlty configuration. - Update `CONTRIBUTING.md` with prerequisites and setup instructions. - Add `phpstan/phpstan-phpunit` dependency to `composer.json`. - Create Lefthook configuration for automated checks. - Refactor currency driver methods to improve structure and usage. - Extend currency enum with comprehensive currency names. - Introduce `MockHttpClientException` for better error handling in tests. - Update various tests for new and modified functionality.
|
|
||
| $response = $this->apiRequest('convert', $params); | ||
|
|
||
| $rate = BigDecimal::of($this->responseString($response, 'result', static::class)) |
| $response = $this->apiRequest('convert', $params); | ||
|
|
||
| $rate = BigDecimal::of($this->responseString($response, 'result', static::class)) | ||
| ->dividedBy(BigDecimal::of((string) $this->amount), ConversionResult::DEFAULT_SCALE, RoundingMode::HALF_UP); |
| * | ||
| * @return array<string, BigDecimal|float|int|string> | ||
| */ | ||
| protected function responseRates(array $response, string $key, string $provider): array |
|
|
||
| $normalised = []; | ||
| foreach ($rates as $currency => $rate) { | ||
| if (!$rate instanceof BigDecimal && !is_float($rate) && !is_int($rate) && !is_string($rate)) { |
| throw new ApiException('CurrencyAPI response did not contain a converted value.'); | ||
| } | ||
|
|
||
| $rate = BigDecimal::of((string) $converted) |
| $this->assertSame('United States Dollar', Currency::USD->displayName()); | ||
| } | ||
|
|
||
| #[Test] |
| #[Test] | ||
| public function try_from_code_returns_matching_case(): void | ||
| { | ||
| $this->assertSame(Currency::USD, Currency::tryFromCode('USD')); |
| public function try_from_code_returns_matching_case(): void | ||
| { | ||
| $this->assertSame(Currency::USD, Currency::tryFromCode('USD')); | ||
| $this->assertNull(Currency::tryFromCode('XYZ')); |
| $this->assertNull(Currency::tryFromCode('XYZ')); | ||
| } | ||
|
|
||
| #[Test] |
| #[Test] | ||
| public function code_helper_coerces_strings_and_enum_values(): void | ||
| { | ||
| $this->assertSame('USD', Currency::code('USD')); |
…stan - Apply #[Override] to driver methods so Rector's dry-run gate passes on PHP 8.3+ - Switch CI coverage driver from xdebug to pcov (matches local docs, faster) - Disable qlty's phpstan plugin: it runs without composer autoload and produces ~100 false positives for PSR-18 / PHPUnit attribute classes; CI's phpstan run already covers this with the project's autoloader - Document local pcov/xdebug install in CONTRIBUTING.md so phpunit's failOnWarning config doesn't surprise contributors
| $this->assertSame('2013-12-24', $result->getDate()); | ||
| $this->assertSame('1.636492', (string) $result->rate(Currency::USD)); | ||
| $this->assertSame('1.196476', (string) $result->rate(Currency::EUR)); | ||
| $this->assertSame('1.739516', (string) $result->rate(Currency::CAD)); |
| $this->assertSame('2001-02-16', $result->getDate()); | ||
| $this->assertSame('3.67246', (string) $result->rate(Currency::AED)); | ||
| $this->assertSame('144.529793', (string) $result->rate(Currency::ALL)); | ||
| $this->assertSame('1.79', (string) $result->rate(Currency::ANG)); |
Override the lint driver to install composer deps (so PSR-18, PHPUnit attributes, and project classes resolve), point phpstan at the project's autoloader, and keep phpstan.neon at the project root so its relative ignoreErrors paths still match. Restores PR-comment mode without false positives — verified locally via `qlty check --filter=phpstan`.
| $this->assertSame('2013-12-24', $result->getDate()); | ||
| $this->assertSame('1.636492', (string) $result->rate(Currency::USD)); | ||
| $this->assertSame('1.196476', (string) $result->rate(Currency::EUR)); | ||
| $this->assertSame('1.739516', (string) $result->rate(Currency::CAD)); |
| $this->assertSame('2001-02-16', $result->getDate()); | ||
| $this->assertSame('3.67246', (string) $result->rate(Currency::AED)); | ||
| $this->assertSame('144.529793', (string) $result->rate(Currency::ALL)); | ||
| $this->assertSame('1.79', (string) $result->rate(Currency::ANG)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Modernizes
php-currency-apifor v2 with a stricter PHP 8.3+ baseline, PSR HTTP abstractions, precise decimal math, updated provider support, and a refreshed test/tooling/docs surface.Currencybacked enum while keepingSymbolas a deprecation shim.brick/mathBigDecimal.frankfurtercurrencyapifastforexexchangeratesapifor APILayer’s current endpoint and implement conversion support.DriverFactoryregistration while preservingDriverFactory::make().