From b50e49358a96def4b82fb6bac74a120cec9629d6 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Thu, 16 Feb 2023 17:06:45 +0100 Subject: [PATCH] Add L10 support (#20) * Add L10 support * Upgrade phpstan * Set `archtechx/helpers` version * Fix PHPStan errors * Try using older PHPStan version * Revert PHPStan downgrade * Delete immutability tests * Bring back immutability tests * Correct typehint * Update immutability tests * Remove L8 support * Allow PHP 8.0, run tests for 8.0 as well * Swap Laravel 9 & 10 * Add setup-php step * Revert formatting changes * Fix formatting * Revert adding setup-php * Try adding setup-php * Change formatting * Remove PHP 8.0 * Fix formatting --- .github/workflows/ci.yml | 6 +++++- composer.json | 16 ++++++++-------- src/Concerns/RegistersCurrencies.php | 5 ++++- src/Currency.php | 1 + src/Money.php | 1 + tests/Pest/MoneyTest.php | 16 ++++++++++------ 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33a7079..9e309df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,10 +16,14 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - laravel: [8, 9] + laravel: [9, 10] steps: - uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' - name: Install composer dependencies run: composer require "illuminate/support:^${{ matrix.laravel }}.0" - name: Run tests diff --git a/composer.json b/composer.json index dc9bc69..42e5035 100644 --- a/composer.json +++ b/composer.json @@ -24,16 +24,16 @@ } }, "require": { - "php": "^8.0", - "illuminate/support": "^8.0|^9.0", - "archtechx/helpers": "*" + "php": "^8.1", + "illuminate/support": "^9.0|^10.0", + "archtechx/helpers": "^0.3.1" }, "require-dev": { - "orchestra/testbench": "^6.9|^7.0", - "pestphp/pest": "^1.10", - "phpstan/phpstan": "^0.12.92", - "pestphp/pest-plugin-laravel": "^1.1", - "nunomaduro/larastan": "^0.7.10" + "orchestra/testbench": "^7.19|^8.0", + "pestphp/pest": "^1.10|^2.0", + "phpstan/phpstan": "^1.9.8", + "pestphp/pest-plugin-laravel": "^1.1|^2.0", + "nunomaduro/larastan": "^2.4" }, "extra": { "laravel": { diff --git a/src/Concerns/RegistersCurrencies.php b/src/Concerns/RegistersCurrencies.php index db80491..e96b420 100644 --- a/src/Concerns/RegistersCurrencies.php +++ b/src/Concerns/RegistersCurrencies.php @@ -128,7 +128,10 @@ trait RegistersCurrencies } if (class_exists($currency) && (new ReflectionClass($currency))->isSubclassOf(Currency::class)) { - return (new $currency)->code(); + /** @var Currency $currency * */ + $currency = new $currency; + + return $currency->code(); } throw new InvalidCurrencyException( diff --git a/src/Currency.php b/src/Currency.php index 3f071bf..9ae7b3f 100644 --- a/src/Currency.php +++ b/src/Currency.php @@ -8,6 +8,7 @@ use ArchTech\Money\Exceptions\InvalidCurrencyException; use Illuminate\Contracts\Support\Arrayable; use JsonSerializable; +/** @implements Arrayable */ class Currency implements Arrayable, JsonSerializable { /** Code of the currency (e.g. 'CZK'). */ diff --git a/src/Money.php b/src/Money.php index 16f0c3c..6eaa6a7 100644 --- a/src/Money.php +++ b/src/Money.php @@ -8,6 +8,7 @@ use Illuminate\Contracts\Support\Arrayable; use JsonSerializable; use Livewire\Wireable; +/** @implements Arrayable */ final class Money implements JsonSerializable, Arrayable, Wireable { protected int $value; diff --git a/tests/Pest/MoneyTest.php b/tests/Pest/MoneyTest.php index b8055f1..f895818 100644 --- a/tests/Pest/MoneyTest.php +++ b/tests/Pest/MoneyTest.php @@ -7,19 +7,23 @@ use ArchTech\Money\Tests\Currencies\CZK; use ArchTech\Money\Tests\Currencies\EUR; test('Money value is immutable', function () { - pest()->expectError(); - $money = money(100); - $money->value = 200; + try { + $money->value = 200; + } catch (Throwable $th) { + expect($th)->toBeInstanceOf(Error::class); + } }); test('Money currency is immutable', function () { - pest()->expectError(); - $money = money(100); - $money->currency = 'EUR'; + try { + $money->currency = 'EUR'; + } catch (Throwable $th) { + expect($th)->toBeInstanceOf(Error::class); + } }); test('money can be created from a decimal value', function () {