Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: require PHP 8.2 or later #11

Merged
merged 2 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 3 additions & 11 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;
use Worksome\CodingStyle\WorksomeEcsConfig;


return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__DIR__ . '/tests',
__DIR__ . '/config',
]);

WorksomeEcsConfig::setup($ecsConfig);
};
23 changes: 23 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Worksome\CodingStyle\WorksomeRectorConfig;

return static function (RectorConfig $rectorConfig): void {
WorksomeRectorConfig::setup($rectorConfig);

$rectorConfig->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);
};
6 changes: 4 additions & 2 deletions src/Commands/ViewLatestRatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/Contracts/Actions/ValidatesCurrencyCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ interface ValidatesCurrencyCodes
{
/**
* @param non-empty-array<int, string> $currencyCodes
*
* @return non-empty-array<int, string>
*
* @throws InvalidCurrencyCodeException
*/
public function __invoke(array $currencyCodes): array;
Expand Down
1 change: 1 addition & 0 deletions src/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function fake(array $rates = []): void

/**
* @param non-empty-array<int, string> $currencies
*
* @throws InvalidCurrencyCodeException
*/
public function rates(string $baseCurrency, array $currencies): Rates
Expand Down
1 change: 0 additions & 1 deletion src/ExchangeRateProviders/CachedProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/ExchangeRateProviders/FixerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function getRates(string $baseCurrency, array $currencies): Rates

/**
* @param array<int, string> $currencies
*
* @return Collection<string, mixed>
*
* @throws RequestException
*/
private function makeRequest(string $baseCurrency, array $currencies): Collection
Expand Down
3 changes: 3 additions & 0 deletions src/ExchangeRateProviders/FrankfurterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public function getRates(string $baseCurrency, array $currencies): Rates

/**
* @param array<int, string> $currencies
*
* @return Collection<string, mixed>
*
* @throws RequestException
*/
private function makeRequest(string $baseCurrency, array $currencies): Collection
Expand All @@ -62,6 +64,7 @@ private function client(): PendingRequest

/**
* @param Collection<string, mixed> $data
*
* @return CarbonImmutable
*/
private function getRetreivedAt(Collection $data): CarbonImmutable
Expand Down
1 change: 0 additions & 1 deletion src/ExchangeRateProviders/NullProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down
4 changes: 2 additions & 2 deletions src/Facades/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 0 additions & 4 deletions src/Support/ExchangeRateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function createFixerDriver(): FixerProvider
));

return new FixerProvider(
// @phpstan-ignore-next-line
$this->container->make(Factory::class),
$apiKey,
);
Expand All @@ -44,23 +43,20 @@ public function createFixerDriver(): FixerProvider
public function createExchangeRateDriver(): ExchangeRateHostProvider
{
return new ExchangeRateHostProvider(
// @phpstan-ignore-next-line
$this->container->make(Factory::class),
);
}

public function createFrankfurterDriver(): FrankfurterProvider
{
return new FrankfurterProvider(
// @phpstan-ignore-next-line
$this->container->make(Factory::class),
);
}

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')),
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/FakeExchangeRateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public function assertRetrievedRates(int $times = 1): self

/**
* @param non-empty-array<int, string> $currencies
*
* @return non-empty-array<string, float>
*/
private function getRatesArray(array $currencies): array
{
// @phpstan-ignore-next-line
return array_merge(array_fill_keys($currencies, 1.0), $this->predefinedRates);
}
}
8 changes: 4 additions & 4 deletions tests/Feature/Commands/ViewLatestRatesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -24,21 +24,21 @@

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();
});

it('retrieves rates using the ExchangeRateProvider', function () {
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();
Expand Down
4 changes: 3 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}

Expand Down
8 changes: 6 additions & 2 deletions tests/Unit/ExchangeRateProviders/CachedProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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.
]);
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

use Carbon\Carbon;
use GuzzleHttp\Promise\Create;
use GuzzleHttp\Psr7\Response;
use Illuminate\Http\Client\Factory;
use Illuminate\Http\Client\Request;
use Illuminate\Http\Client\RequestException;
use Worksome\Exchange\ExchangeRateProviders\ExchangeRateHostProvider;
use Worksome\Exchange\Support\Rates;
use GuzzleHttp\Promise\Create;
use Illuminate\Http\Client\Factory;

it('is able to make a real call to the API', function () {
$client = new Factory();
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/ExchangeRateProviders/FixerProviderTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

use Carbon\Carbon;
use GuzzleHttp\Promise\Create;
use GuzzleHttp\Psr7\Response;
use Illuminate\Http\Client\Factory;
use Illuminate\Http\Client\Request;
use Illuminate\Http\Client\RequestException;
use Worksome\Exchange\ExchangeRateProviders\FixerProvider;
use Worksome\Exchange\Support\Rates;
use GuzzleHttp\Promise\Create;
use Illuminate\Http\Client\Factory;

it('is able to make a real call to the API', function () {
$client = new Factory();
Expand Down