diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 21fa622..591ab8a 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -16,7 +16,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.2' coverage: none - name: Install composer dependencies diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a41d09d..42b522f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -16,17 +16,9 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - php: [8.0, 8.1] - laravel: [8.*, 9.*] + php: [8.2] + laravel: [9.*] stability: [prefer-lowest, prefer-stable] - exclude: - - os: windows-latest - php: 8.1 - include: - - laravel: 8.* - testbench: ^6.23 - - laravel: 9.* - testbench: ^7.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} @@ -48,7 +40,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Execute tests diff --git a/composer.json b/composer.json index d378237..fe1e3d6 100644 --- a/composer.json +++ b/composer.json @@ -16,22 +16,22 @@ } ], "require": { - "php": "^8.0 || ^8.1", - "illuminate/contracts": "^8.80 || ^9.0", - "nunomaduro/termwind": "^1.10", - "spatie/laravel-package-tools": "^1.9.2" + "php": "^8.2", + "illuminate/contracts": "^9.46", + "nunomaduro/termwind": "^1.13", + "spatie/laravel-package-tools": "^1.13.8" }, "require-dev": { "guzzlehttp/guzzle": "^7.4", - "nunomaduro/collision": "^5.10 || ^6.0", - "nunomaduro/larastan": "^1.0 || ^2.0", - "orchestra/testbench": "^6.22 || ^7.0", - "pestphp/pest": "^1.21", + "nunomaduro/collision": "^6.3", + "nunomaduro/larastan": "^2.3", + "orchestra/testbench": "^7.18", + "pestphp/pest": "^1.22", "pestphp/pest-plugin-laravel": "^1.1", "pestphp/pest-plugin-parallel": "^1.0", "spatie/laravel-ray": "^1.26", - "worksome/coding-style": "^0.13.0", - "worksome/pest-plugin-silence": "^0.1" + "worksome/coding-style": "^2.3", + "worksome/pest-plugin-silence": "^0.1.2" }, "autoload": { "psr-4": { @@ -45,11 +45,11 @@ } }, "scripts": { - "lint": "vendor/bin/phpcbf", + "lint": "vendor/bin/ecs --fix", "test:unit": "vendor/bin/pest", "test:coverage": "vendor/bin/pest --coverage", "test:types": "vendor/bin/phpstan analyse", - "test:style": "vendor/bin/phpcs -n", + "test:style": "vendor/bin/ecs", "test": [ "@test:style", "@test:types", diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..1916269 --- /dev/null +++ b/ecs.php @@ -0,0 +1,17 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + __DIR__ . '/config', + ]); + + WorksomeEcsConfig::setup($ecsConfig); +}; diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..e1706e6 --- /dev/null +++ b/rector.php @@ -0,0 +1,23 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + // Define extra rule sets to be applied + $rectorConfig->sets([ + // SetList::DEAD_CODE, + ]); + + // Register extra a single rules + // $rectorConfig->rule(ClassOnObjectRector::class); +}; diff --git a/src/Commands/ViewLatestRatesCommand.php b/src/Commands/ViewLatestRatesCommand.php index 5c2020d..0f008f8 100644 --- a/src/Commands/ViewLatestRatesCommand.php +++ b/src/Commands/ViewLatestRatesCommand.php @@ -19,7 +19,7 @@ final class ViewLatestRatesCommand extends Command use HasUsefulConsoleMethods; public $signature = 'exchange:rates - {base_currency? : The base currency to convert from.} + {base-currency? : The base currency to convert from.} {currencies?* : Any number of currencies to fetch exchange rates for.}'; public $description = 'Retrieve exchange rates for a given set of currencies.'; @@ -53,7 +53,9 @@ private function data(CurrencyCodeProvider $currencyCodeProvider): array $givenCurrencies = $this->argument('currencies'); return [ - 'base_currency' => $this->argument('base_currency') ?? $this->ask('Which base currency do you want to use?'), + 'base_currency' => $this->argument('base-currency') ?? $this->ask( + 'Which base currency do you want to use?' + ), 'currencies' => count($givenCurrencies) > 0 ? $givenCurrencies : $this->choice( 'Which currencies do you want to fetch exchange rates for?', $currencyCodeProvider->all(), diff --git a/src/Contracts/Actions/ValidatesCurrencyCodes.php b/src/Contracts/Actions/ValidatesCurrencyCodes.php index ecb6a9e..6168733 100644 --- a/src/Contracts/Actions/ValidatesCurrencyCodes.php +++ b/src/Contracts/Actions/ValidatesCurrencyCodes.php @@ -10,7 +10,9 @@ interface ValidatesCurrencyCodes { /** * @param non-empty-array $currencyCodes + * * @return non-empty-array + * * @throws InvalidCurrencyCodeException */ public function __invoke(array $currencyCodes): array; diff --git a/src/Exchange.php b/src/Exchange.php index 8b0e860..7814657 100755 --- a/src/Exchange.php +++ b/src/Exchange.php @@ -28,6 +28,7 @@ public function fake(array $rates = []): void /** * @param non-empty-array $currencies + * * @throws InvalidCurrencyCodeException */ public function rates(string $baseCurrency, array $currencies): Rates diff --git a/src/ExchangeRateProviders/CachedProvider.php b/src/ExchangeRateProviders/CachedProvider.php index fe0ae62..e495f3d 100644 --- a/src/ExchangeRateProviders/CachedProvider.php +++ b/src/ExchangeRateProviders/CachedProvider.php @@ -23,7 +23,6 @@ public function getRates(string $baseCurrency, array $currencies): Rates { $currenciesForKey = implode(',', Arr::sort($currencies)); - // @phpstan-ignore-next-line return $this->cache->remember( "{$this->key}:{$baseCurrency}:{$currenciesForKey}", $this->ttl, diff --git a/src/ExchangeRateProviders/FixerProvider.php b/src/ExchangeRateProviders/FixerProvider.php index bac847b..9d8de74 100644 --- a/src/ExchangeRateProviders/FixerProvider.php +++ b/src/ExchangeRateProviders/FixerProvider.php @@ -38,7 +38,9 @@ public function getRates(string $baseCurrency, array $currencies): Rates /** * @param array $currencies + * * @return Collection + * * @throws RequestException */ private function makeRequest(string $baseCurrency, array $currencies): Collection diff --git a/src/ExchangeRateProviders/FrankfurterProvider.php b/src/ExchangeRateProviders/FrankfurterProvider.php index ebf12a9..9af7205 100644 --- a/src/ExchangeRateProviders/FrankfurterProvider.php +++ b/src/ExchangeRateProviders/FrankfurterProvider.php @@ -38,7 +38,9 @@ public function getRates(string $baseCurrency, array $currencies): Rates /** * @param array $currencies + * * @return Collection + * * @throws RequestException */ private function makeRequest(string $baseCurrency, array $currencies): Collection @@ -62,6 +64,7 @@ private function client(): PendingRequest /** * @param Collection $data + * * @return CarbonImmutable */ private function getRetreivedAt(Collection $data): CarbonImmutable diff --git a/src/ExchangeRateProviders/NullProvider.php b/src/ExchangeRateProviders/NullProvider.php index 1db38fa..a356434 100644 --- a/src/ExchangeRateProviders/NullProvider.php +++ b/src/ExchangeRateProviders/NullProvider.php @@ -13,7 +13,6 @@ public function getRates(string $baseCurrency, array $currencies): Rates { return new Rates( $baseCurrency, - // @phpstan-ignore-next-line array_fill_keys($currencies, 1.0), now() ); diff --git a/src/Facades/Exchange.php b/src/Facades/Exchange.php index c2bb107..0621d46 100644 --- a/src/Facades/Exchange.php +++ b/src/Facades/Exchange.php @@ -8,8 +8,8 @@ use Worksome\Exchange\Support\Rates; /** - * @method static Rates rates(string $baseCurrency, array $currencies) - * @method static assertRetrievedRates(int $times = 1) + * @method static Rates rates(string $baseCurrency, array $currencies) + * @method static assertRetrievedRates(int $times = 1) * * @see \Worksome\Exchange\Exchange */ diff --git a/src/Support/ExchangeRateManager.php b/src/Support/ExchangeRateManager.php index 4065242..2436efe 100644 --- a/src/Support/ExchangeRateManager.php +++ b/src/Support/ExchangeRateManager.php @@ -35,7 +35,6 @@ public function createFixerDriver(): FixerProvider )); return new FixerProvider( - // @phpstan-ignore-next-line $this->container->make(Factory::class), $apiKey, ); @@ -44,7 +43,6 @@ public function createFixerDriver(): FixerProvider public function createExchangeRateDriver(): ExchangeRateHostProvider { return new ExchangeRateHostProvider( - // @phpstan-ignore-next-line $this->container->make(Factory::class), ); } @@ -52,7 +50,6 @@ public function createExchangeRateDriver(): ExchangeRateHostProvider public function createFrankfurterDriver(): FrankfurterProvider { return new FrankfurterProvider( - // @phpstan-ignore-next-line $this->container->make(Factory::class), ); } @@ -60,7 +57,6 @@ public function createFrankfurterDriver(): FrankfurterProvider public function createCacheDriver(): CachedProvider { return new CachedProvider( - // @phpstan-ignore-next-line $this->container->make(Repository::class), // @phpstan-ignore-next-line $this->driver($this->config->get('exchange.services.cache.strategy')), diff --git a/src/Testing/FakeExchangeRateProvider.php b/src/Testing/FakeExchangeRateProvider.php index 3bacfb3..35f6383 100644 --- a/src/Testing/FakeExchangeRateProvider.php +++ b/src/Testing/FakeExchangeRateProvider.php @@ -47,11 +47,11 @@ public function assertRetrievedRates(int $times = 1): self /** * @param non-empty-array $currencies + * * @return non-empty-array */ private function getRatesArray(array $currencies): array { - // @phpstan-ignore-next-line return array_merge(array_fill_keys($currencies, 1.0), $this->predefinedRates); } } diff --git a/tests/Feature/Commands/ViewLatestRatesCommandTest.php b/tests/Feature/Commands/ViewLatestRatesCommandTest.php index 72659bb..005bd10 100644 --- a/tests/Feature/Commands/ViewLatestRatesCommandTest.php +++ b/tests/Feature/Commands/ViewLatestRatesCommandTest.php @@ -13,7 +13,7 @@ it('asks for currencies if none are provided', function () { $this - ->artisan('exchange:rates', ['base_currency' => 'GBP']) + ->artisan('exchange:rates', ['base-currency' => 'GBP']) ->expectsChoice( 'Which currencies do you want to fetch exchange rates for?', ['EUR', 'USD'], @@ -24,13 +24,13 @@ it('fails if an invalid base currency is passed', function () { $this - ->artisan('exchange:rates', ['base_currency' => 'FOO', 'currencies' => ['GBP', 'USD']]) + ->artisan('exchange:rates', ['base-currency' => 'FOO', 'currencies' => ['GBP', 'USD']]) ->assertFailed(); }); it('fails if an invalid conversion currency is passed', function () { $this - ->artisan('exchange:rates', ['base_currency' => 'GBP', 'currencies' => ['FOO', 'USD']]) + ->artisan('exchange:rates', ['base-currency' => 'GBP', 'currencies' => ['FOO', 'USD']]) ->assertFailed(); }); @@ -38,7 +38,7 @@ Exchange::fake(['GBP' => 1.2]); $this - ->artisan('exchange:rates', ['base_currency' => 'GBP', 'currencies' => ['EUR', 'USD']]) + ->artisan('exchange:rates', ['base-currency' => 'GBP', 'currencies' => ['EUR', 'USD']]) ->assertSuccessful(); Exchange::assertRetrievedRates(); diff --git a/tests/TestCase.php b/tests/TestCase.php index c7e3dab..647649a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -17,7 +17,9 @@ protected function setUp(): void Termwind::renderUsing(new BufferedOutput()); Factory::guessFactoryNamesUsing( - fn (string $modelName) => 'Worksome\\Exchange\\Database\\Factories\\' . class_basename($modelName) . 'Factory' + fn (string $modelName) => 'Worksome\\Exchange\\Database\\Factories\\' . class_basename( + $modelName + ) . 'Factory' ); } diff --git a/tests/Unit/ExchangeRateProviders/CachedProviderTest.php b/tests/Unit/ExchangeRateProviders/CachedProviderTest.php index 0441cdd..c9f1c9d 100644 --- a/tests/Unit/ExchangeRateProviders/CachedProviderTest.php +++ b/tests/Unit/ExchangeRateProviders/CachedProviderTest.php @@ -2,10 +2,10 @@ use Illuminate\Cache\ArrayStore; use Illuminate\Contracts\Cache\Repository; +use Mockery as m; use Worksome\Exchange\ExchangeRateProviders\CachedProvider; use Worksome\Exchange\Support\Rates; use Worksome\Exchange\Testing\FakeExchangeRateProvider; -use Mockery as m; it('calls the underlying strategy', function () { $cache = new \Illuminate\Cache\Repository(new ArrayStore()); @@ -45,5 +45,9 @@ })->with([ ['GBP', ['EUR'], 'foo:GBP:EUR'], ['GBP', ['EUR', 'USD'], 'foo:GBP:EUR,USD'], - ['GBP', ['USD', 'EUR'], 'foo:GBP:EUR,USD'], // It should sort the order so that we don't make unnecessary requests just because the order was altered. + [ + 'GBP', + ['USD', 'EUR'], + 'foo:GBP:EUR,USD' + ], // It should sort the order so that we don't make unnecessary requests just because the order was altered. ]); diff --git a/tests/Unit/ExchangeRateProviders/ExchangeRateHostProviderTest.php b/tests/Unit/ExchangeRateProviders/ExchangeRateHostProviderTest.php index 69f4920..09719a4 100644 --- a/tests/Unit/ExchangeRateProviders/ExchangeRateHostProviderTest.php +++ b/tests/Unit/ExchangeRateProviders/ExchangeRateHostProviderTest.php @@ -1,13 +1,13 @@