Skip to content

Commit b50e493

Browse files
authored
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
1 parent b1b02f4 commit b50e493

File tree

6 files changed

+29
-16
lines changed

6 files changed

+29
-16
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ jobs:
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
laravel: [8, 9]
19+
laravel: [9, 10]
2020

2121
steps:
2222
- uses: actions/checkout@v2
23+
- name: Setup PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: '8.1'
2327
- name: Install composer dependencies
2428
run: composer require "illuminate/support:^${{ matrix.laravel }}.0"
2529
- name: Run tests

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
}
2525
},
2626
"require": {
27-
"php": "^8.0",
28-
"illuminate/support": "^8.0|^9.0",
29-
"archtechx/helpers": "*"
27+
"php": "^8.1",
28+
"illuminate/support": "^9.0|^10.0",
29+
"archtechx/helpers": "^0.3.1"
3030
},
3131
"require-dev": {
32-
"orchestra/testbench": "^6.9|^7.0",
33-
"pestphp/pest": "^1.10",
34-
"phpstan/phpstan": "^0.12.92",
35-
"pestphp/pest-plugin-laravel": "^1.1",
36-
"nunomaduro/larastan": "^0.7.10"
32+
"orchestra/testbench": "^7.19|^8.0",
33+
"pestphp/pest": "^1.10|^2.0",
34+
"phpstan/phpstan": "^1.9.8",
35+
"pestphp/pest-plugin-laravel": "^1.1|^2.0",
36+
"nunomaduro/larastan": "^2.4"
3737
},
3838
"extra": {
3939
"laravel": {

src/Concerns/RegistersCurrencies.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ public function getCode(Currency|string $currency): string
128128
}
129129

130130
if (class_exists($currency) && (new ReflectionClass($currency))->isSubclassOf(Currency::class)) {
131-
return (new $currency)->code();
131+
/** @var Currency $currency * */
132+
$currency = new $currency;
133+
134+
return $currency->code();
132135
}
133136

134137
throw new InvalidCurrencyException(

src/Currency.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Contracts\Support\Arrayable;
99
use JsonSerializable;
1010

11+
/** @implements Arrayable<string, string|int|float> */
1112
class Currency implements Arrayable, JsonSerializable
1213
{
1314
/** Code of the currency (e.g. 'CZK'). */

src/Money.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use JsonSerializable;
99
use Livewire\Wireable;
1010

11+
/** @implements Arrayable<string, string|int> */
1112
final class Money implements JsonSerializable, Arrayable, Wireable
1213
{
1314
protected int $value;

tests/Pest/MoneyTest.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@
77
use ArchTech\Money\Tests\Currencies\EUR;
88

99
test('Money value is immutable', function () {
10-
pest()->expectError();
11-
1210
$money = money(100);
1311

14-
$money->value = 200;
12+
try {
13+
$money->value = 200;
14+
} catch (Throwable $th) {
15+
expect($th)->toBeInstanceOf(Error::class);
16+
}
1517
});
1618

1719
test('Money currency is immutable', function () {
18-
pest()->expectError();
19-
2020
$money = money(100);
2121

22-
$money->currency = 'EUR';
22+
try {
23+
$money->currency = 'EUR';
24+
} catch (Throwable $th) {
25+
expect($th)->toBeInstanceOf(Error::class);
26+
}
2327
});
2428

2529
test('money can be created from a decimal value', function () {

0 commit comments

Comments
 (0)