Skip to content

Commit

Permalink
Add L10 support (#20)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lukinovec authored Feb 16, 2023
1 parent b1b02f4 commit b50e493
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
5 changes: 4 additions & 1 deletion src/Concerns/RegistersCurrencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ public function getCode(Currency|string $currency): string
}

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(
Expand Down
1 change: 1 addition & 0 deletions src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Contracts\Support\Arrayable;
use JsonSerializable;

/** @implements Arrayable<string, string|int|float> */
class Currency implements Arrayable, JsonSerializable
{
/** Code of the currency (e.g. 'CZK'). */
Expand Down
1 change: 1 addition & 0 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use JsonSerializable;
use Livewire\Wireable;

/** @implements Arrayable<string, string|int> */
final class Money implements JsonSerializable, Arrayable, Wireable
{
protected int $value;
Expand Down
16 changes: 10 additions & 6 deletions tests/Pest/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,23 @@
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 () {
Expand Down

0 comments on commit b50e493

Please sign in to comment.